def test_get_map_after_update(): points = Points([]) mapped = points.map(lambda x, y: y * 2) callback_count = 0 assert np.array_equal(mapped.sample_points(), []) def callback(*args): nonlocal callback_count callback_count += 1 assert np.array_equal(mapped.sample_points(), [(0, 2), (1, 4), (2, 6)]) points.add_observer(end=callback) points.append_list(test_util.point_gen([1, 2, 3])) assert callback_count == 1
def test_reset(): update_interval = None def did_update(domain): nonlocal update_interval update_interval = domain points = [(0, 1), (1, 2), (2, 3)] pf = Points(points, uniform=False) pf.reset() assert pf.domain.is_empty pf = Points(points, uniform=False) update_interval = None pf.add_observer(end=did_update) assert pf(1) == 2 assert pf(2) == 3 pf.reset((2, 2)) assert pf(1) == 2 assert pf(2) is None assert update_interval.start == 1 assert update_interval.start_open assert update_interval.end == 2 assert not update_interval.end_open pf = Points(points, uniform=False) update_interval = None pf.add_observer(end=did_update) assert pf(0) == 1 assert pf(1) == 2 assert pf(2) == 3 pf.reset((1, 1)) assert pf(0) == 1 assert pf(1) == 2 assert pf(2) == 3 assert update_interval.start == 0 assert update_interval.start_open assert update_interval.end == 2 assert update_interval.end_open pf = Points(points, uniform=True) with pytest.raises(Exception): pf.reset((1, 1))