示例#1
0
def test_round():
    assert Interval(1.2, 3.4).round() == (1, 3)
    assert Interval(1.2, 3.4).round(method=math.floor) == (1, 3)
    assert Interval(1.2, 3.4).round(method=math.ceil) == (2, 4)
    assert Interval.open_closed(1.2, 3.4).round() == Interval.open_closed(1, 3)
    assert Interval.closed_open(1.2, 3.4).round() == Interval.closed_open(1, 3)
    assert Interval.empty().round() == Interval.empty()
示例#2
0
def test_intersects():
    assert Interval.closed(1, 3).intersects(Interval.closed(2, 3))
    assert Interval.closed(1, 3).intersects((2, 3))
    assert Interval.closed(1, 3).intersects((1, 3))
    assert Interval.closed(1, 3).intersects(Interval.open(1, 3))

    assert Interval.closed(1, 3).intersects(Interval.closed(3, 4))
    assert not Interval.closed(1, 3).intersects(Interval.open(3, 4))
    assert not Interval.open(1, 3).intersects(Interval.closed(3, 4))

    assert Interval.point(3).intersects(Interval.closed(3, 4))
    assert Interval.point(3).intersects(Interval.closed(1, 3))
    assert not Interval.point(3).intersects(Interval.open(3, 4))
    assert not Interval.point(3).intersects(Interval.open(1, 3))

    assert Interval.closed(1, 3).intersects(Interval.closed(0, 1))
    assert not Interval.closed(1, 3).intersects(Interval.open(0, 1))
    assert not Interval.open(1, 3).intersects(Interval.closed(0, 1))

    assert not Interval.closed(1, 3).intersects(Interval.closed(4, 5))
    assert not Interval.closed(1, 3).intersects(Interval.closed(-2, 0))

    assert not Interval.closed(1, 3).intersects(Interval.empty())
    assert Interval.closed(1, 3).intersects(Interval.infinite())

    assert not Interval.point(1).intersects(Interval.open_closed(1, 2))
示例#3
0
def test_sample_points():
    original_quotes_points = Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2),
                                                      (2, 3.1, 1.9, 3),
                                                      (3, 5.1, 2.9, 5)],
                                                     t_start=0,
                                                     t_step=1)
    f = Quotes(1, quote_points=original_quotes_points)

    ps = f.sample_points()
    assert ps == original_quotes_points

    ps = f.sample_points(domain=Interval.open_closed(1, 2))
    assert ps == original_quotes_points[1:3]

    ps = f.sample_points(domain=Interval.closed(1, 2))
    assert ps == original_quotes_points[1:3]

    ps = f.sample_points(domain=Interval.closed(3, 4))
    assert ps == []

    ps = f.sample_points(domain=Interval.closed(-1, 0))
    assert ps == original_quotes_points[0:1]
示例#4
0
def test_intersection_inf():
    assert Interval.intersection([Interval.gte(100), (98, 101)]) == (100, 101)
    assert Interval.intersection([Interval.point(100), Interval.open_closed(100, 101)]) == Interval.empty()
示例#5
0
def test_arithmetic():
    assert Interval(1, 3) + (2, 4) == (1, 4)
    assert (1, 3) + Interval(2, 4) == (1, 4)

    assert Interval.open(1, 3) + (2, 4) == Interval.open_closed(1, 4)
    assert (1, 3) + Interval.open(2, 4) == Interval.closed_open(1, 4)