def test_reset_open_interval(): points = [(0, 1), (1, 5), (2, 3)] pf = Points(points, uniform=False) assert pf(1) == 5 pf.reset(domain=Interval.open(0, 2)) assert pf(0) == 1 assert pf(1) == 2 assert pf(2) == 3
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))
def test_reset_closed_interval(): points = [(0, 1), (1, 5), (2, 3), (3, 4)] pf = Points(points, uniform=False) assert pf(1) == 5 pf.reset(domain=Interval.closed(1, 2)) assert pf(1) == 2