def test_update_from_empty(): points = Points([]) f = points.extension('tangent', start=True, end=True) assert f(0) is None points.append_list(test_util.point_gen([3, 1, 2])) assert f(0) == 3 assert f(1) == 1 assert f(2) == 2 assert f(3) == 3
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_append_to_empty(): points = Points([]) sma = points.sma(2) points.append_list(test_util.point_gen([1, 2, 3, 4], t_start=10)) assert np.allclose(sma.sample_points(), [(11, 1.5), (12, 2.5), (13, 3.5)])
def test_update_ema_from_empty_non_zero_start(): points = Points([]) f = points.ema(0.5, is_period=False) points.append_list([(1, 1), (2, 2), (3, 1)]) assert np.allclose(f.sample_points(), [(1, 1), (2, 1.5), (3, 1.25)])
def test_update_ema_from_empty(): points = Points([]) f = points.ema(0.5, is_period=False) points.append_list(test_util.point_gen([1, 2, 1])) assert np.allclose(f.sample_points(), [(0, 1), (1, 1.5), (2, 1.25)])
def test_update_from_empty(): points = Points([]) mapped = points.map(lambda x, y: y * 2) assert np.array_equal(mapped.sample_points(), []) points.append_list(test_util.point_gen([1, 2, 3])) assert np.array_equal(mapped.sample_points(), [(0, 2), (1, 4), (2, 6)])