def test_duplicate_multiple_nested_function_update(): points = Points([]) f = (points * 0.5 + points * 0.5) * 2 points.append((0, 1)) assert f.is_updating is False assert f.domain == Interval.point(0) assert f.y(0) == 2 points.append((1, 1)) assert f.is_updating is False assert f.domain == Interval(0, 1) assert f.y(1) == 2
def test_duplicate_function_update(): points = Points([]) f = points + points points.append((0, 1)) assert points.is_updating is False assert f.is_updating is False assert f.domain == Interval.point(0) assert f.y(0) == 2 points.append((1, 1)) assert points.is_updating is False assert f.is_updating is False assert f.domain == Interval(0, 1) assert f.y(1) == 2
def test_update(): p1 = Points([(0, 1), (1, 1)]) p2 = Points([(2, 2), (4, 2)]) f = Aggregate([p1, p2], tfm=lambda x, ys: sum(ys), union=False) assert f.domain.is_empty assert f(0) is None assert f(1.5) is None assert f(3) is None p1.append((2, 1)) assert f.domain.start == 2 assert f.domain.end == 2 assert not f.domain.start_open assert not f.domain.end_open assert f(2) == 3 assert f.is_updating is False p1.append((3, 1)) assert f.domain.start == 2 assert f.domain.end == 3 assert not f.domain.start_open assert not f.domain.end_open assert f(2) == 3 assert f(3) == 3 assert f.is_updating is False p1.append((4, 1)) assert f.domain.start == 2 assert f.domain.end == 4 assert not f.domain.start_open assert not f.domain.end_open assert f(4) == 3 assert f.is_updating is False
def test_nested_update(): p1 = Points([(0, 1), (1, 1)]) p2 = Points([(2, 2), (4, 2)]) f = Aggregate([p1 * 2, p2 * 2], tfm=lambda x, ys: sum(ys)) assert f.domain.is_empty assert f(0) is None assert f(1.5) is None assert f(3) is None p1.append((2, 1)) assert f.domain.start == 2 assert f.domain.end == 2 assert not f.domain.start_open assert not f.domain.end_open assert f(2) == 6 p1.append((3, 1)) assert f.domain.start == 2 assert f.domain.end == 3 assert not f.domain.start_open assert not f.domain.end_open assert f(2) == 6 assert f(3) == 6
def test_multiple_nested_offset_update(): p1 = Points([(0, 1), (1, 1)]) p2 = Points([(2, 2), (4, 2)]) f = (p1.offset(10) * 2 + p2.offset(10) * 2) / 2 assert f.domain.is_empty assert f(10) is None assert f(11.5) is None assert f(13) is None p1.append((2, 1)) assert f.domain.start == 12 assert f.domain.end == 12 assert not f.domain.start_open assert not f.domain.end_open assert f(12) == 3 p1.append((3, 1)) assert f.domain.start == 12 assert f.domain.end == 13 assert not f.domain.start_open assert not f.domain.end_open assert f(12) == 3 assert f(13) == 3
def test_update_from_empty(): p1 = Points([]) f = Aggregate([p1], tfm=lambda x, ys: sum(ys)) assert f(0) is None p1.append((0, 1)) assert f(0) == 1 p1.append((1, 2)) assert f(1) == 2 p1.append((2, 3)) assert f(2) == 3
def test_update_from_empty(): ps = Points([]) assert ps(0) is None ps.append((0, 1)) assert ps.is_updating is False assert ps(0) == 1 ps.append((1, 2)) assert ps.is_updating is False assert ps(1) == 2 ps.append((2, 3)) assert ps.is_updating is False assert ps(2) == 3
def test_update_ema(): points = Points(test_util.point_gen([1, 2, 1])) f = points.ema(0.5, is_period=False) assert f(3) is None points.append((3, 2)) assert f(3) == approx((1.25 + 2.0) * 0.5, abs=0.01)