def test_update_equally_spaced_with_non_equally_spaced(): points = Points([(0, 1), (1, 2)], uniform=False) assert points.is_uniform points.append((3, 4)) assert not points.is_uniform assert points(0) == 1 assert points(1) == 2 assert points(2) == 3 assert points(3) == 4 assert np.array_equal(points.sample_points(), [(0, 1), (1, 2), (3, 4)]) assert np.array_equal(points.sample_points(step=1), [(0, 1), (1, 2), (2, 3), (3, 4)])
def test_ema_alpha(): f = Points(test_util.point_gen([1, 2, 1, 2])).ema(0.5, is_period=False) assert f(0) == 1 assert f(1) == approx(1.5, abs=0.01) assert f(2) == approx(1.25, abs=0.01) assert f(3) == approx((1.25 + 2.0) * 0.5, abs=0.01) assert np.allclose(f.sample_points(), [(0, 1), (1, 1.5), (2, 1.25), (3, (1.25 + 2.0) * 0.5)]) assert np.allclose(f.sample_points(step=2), [(0, 1), (2, 1.25)]) f = Points(test_util.point_gen([1, 2, 1, 2])).ema(0.25, is_period=False) assert f(0) == 1 assert f(1) == approx(0.75 + 2 * 0.25, abs=0.01) assert f(2) == approx((0.75 + 2 * 0.25) * 0.75 + 1 * 0.25, abs=0.01) assert f(3) == approx(((0.75 + 2 * 0.25) * 0.75 + 1 * 0.25) * 0.75 + 2 * 0.25, abs=0.01)
def test_sample(): f = Points(test_util.point_gen([3, 1, 2], t_start=10)).extension('tangent', start=True, end=True) assert np.allclose(f.sample_points(domain=(10, 14)), [(10, 3), (11, 1), (12, 2), (13, 3), (14, 4)])
def test_sample(): ps = Points(test_util.point_gen([1, 2, 3], t_start=1)) assert np.allclose(ps.sample_points(domain=(1, 3), min_step=1e-5), [(1, 1), (2, 2), (3, 3)]) assert np.allclose(ps.sample_points(domain=(1, 3), min_step=1), [(1, 1), (2, 2), (3, 3)]) assert np.allclose(ps.sample_points(domain=(1, 3), min_step=1.5), [(1, 1), (3, 3)]) assert np.allclose(ps.sample_points(domain=(1, 3), step=0.5), [(1, 1), (1.5, 1.5), (2, 2), (2.5, 2.5), (3, 3)]) assert np.allclose(ps.sample_points(domain=(1, 2), step=1), [(1, 1), (2, 2)]) assert np.allclose(ps.sample_points(step=1), [(1, 1), (2, 2), (3, 3)])
def test_sma_period_20_large_step(): f = Points(test_util.point_gen([1, 2, 3, 4], t_step=10)).sma(20, is_period=True) assert np.allclose(f.sample_points(), [(10, 1.5), (20, 2.5), (30, 3.5)])
def test_sample_from_end(): f = Points(test_util.point_gen([1, 2, 3, 4, 5, 6, 7, 8, 9])).sma(3, is_period=True) assert np.allclose(f.sample_points(domain=(7, 8)), [(7, 7), (8, 8)]) assert len(f.accumulated_points._points) == 6
def test_sma_degree_1(): f = Points(test_util.point_gen([1, 2, 3])).sma(1) assert np.allclose(f.sample_points(), [(0, 1), (1, 2), (2, 3)]) assert f(0.5) == 1.5
def test_sma_period_3(): f = Points(test_util.point_gen([1, 2, 3, 4, 5, 6])).sma(3, is_period=True) assert np.allclose(f.sample_points(), [(2, 2), (3, 3), (4, 4), (5, 5)]) assert f(2.5) == 2.5
def test_sma_period_2(): f = Points(test_util.point_gen([1, 2, 3, 4])).sma(2, is_period=True) assert np.allclose(f.sample_points(), [(1, 1.5), (2, 2.5), (3, 3.5)]) assert f(1.5) == 2
def test_sma_period_1(): f = Points(test_util.point_gen([1, 2, 3])).sma(1, is_period=True) assert np.allclose(f.sample_points(), [(0, 1), (1, 2), (2, 3)]) assert f(0.5) == 1.5
def test_sma_degree_2_big_step(): f = Points(test_util.point_gen([1, 2, 3, 4], t_step=10)).sma(2) assert np.allclose(f.sample_points(), [(10, 1.5), (20, 2.5), (30, 3.5)]) assert f(15) == 2
def test_sma_degree_3_non_zero_start(): f = Points([(2, 1), (3, 2), (4, 3), (5, 4)]).sma(3) assert np.allclose(f.sample_points(), [(4, 2), (5, 3)]) assert f(4.5) == 2.5
def test_sma_degree_2(): f = Points(test_util.point_gen([1, 2, 3, 4])).sma(2) assert np.allclose(f.sample_points(), [(1, 1.5), (2, 2.5), (3, 3.5)]) assert f(1.5) == 2