Esempio n. 1
0
def test_interval_union_intersection_1():
    iu1 = IntervalUnion([[0, 100]])
    iu2 = IntervalUnion([[1, 2]])
    iu3 = iu1.intersection(iu2)
    iu4 = iu1 & iu2
    assert iu3.intervals == [Interval(1, 2)]
    assert iu3 == iu4
Esempio n. 2
0
def test_interval_union_issubset_error():
    iu = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    with pytest.raises(Exception) as exinfo:
        assert iu.issubset([[0, 100]])
    msg = (
        "issubset is only defined on Interval and IntervalUnion, "
        "but <class 'list'> was given"
    )
    assert str(exinfo.value) == msg
Esempio n. 3
0
def test_interval_union_union_interval():
    iu1 = IntervalUnion([[0, 1], [2, 3], [4, 5]])
    iu2 = Interval(6, 7)
    iu3 = iu1.union(iu2)
    assert iu3.intervals == [
        Interval(0, 1),
        Interval(2, 3),
        Interval(4, 5),
        Interval(6, 7),
    ]
Esempio n. 4
0
def test_interval_union_union_2():
    iu1 = IntervalUnion([[0, 1], [2, 3], [4, 5]])
    iu2 = IntervalUnion([[-2, -1], [3.5, 3.7]])
    iu3 = iu1.union(iu2)
    assert iu3.intervals == [
        Interval(-2, -1),
        Interval(0, 1),
        Interval(2, 3),
        Interval(3.5, 3.7),
        Interval(4, 5),
    ]
Esempio n. 5
0
def test_interval_union():
    i01 = Interval(0, 1)
    assert Interval(None, None).union(Interval(42, 1337)) == Interval(42, 1337)
    assert Interval(42, 1337).union(Interval(None, None)) == Interval(42, 1337)
    assert i01.union(Interval(1, 3)) == Interval(0, 3)
    assert i01.union(Interval(2, 4)) == IntervalUnion([[0, 1], [2, 4]])
    assert i01.union(Interval(3, 5)) == IntervalUnion([[0, 1], [3, 5]])
    assert i01.union(Interval(-1, 6)) == Interval(-1, 6)
    assert Interval(1, 3).union(Interval(2, 4)) == Interval(1, 4)
    assert Interval(1, 3).union(Interval(3, 5)) == Interval(1, 5)
    assert Interval(1, 3).union(Interval(-1, 6)) == Interval(-1, 6)
    assert Interval(2, 4).union(Interval(3, 5)) == Interval(2, 5)
    assert Interval(2, 4).union(Interval(-1, 6)) == Interval(-1, 6)
    assert Interval(3, 5).union(Interval(-1, 6)) == Interval(-1, 6)
Esempio n. 6
0
def test_interval_issubset_interval_union():
    """
    * Neither of both is empty.
    * i2 is a subset of i1
    * i2 is an intervalUnion
    """
    i1 = Interval(6, 7)
    i2 = IntervalUnion([[2, 3], [5, 7]])
    assert i1.issubset(i2)
Esempio n. 7
0
def test_interval_union_issubset_part():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = IntervalUnion([[20, 30], [40, 50]])
    assert not iu1.issubset(iu2)
    assert iu2.issubset(iu1)
Esempio n. 8
0
def test_interval_union_intersection_error():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = [[-1, 60]]
    with pytest.raises(RuntimeError) as exinfo:
        iu1.intersection(iu2)
    assert str(exinfo.value) == "Intersection with type=<class 'list'> not supported"
Esempio n. 9
0
def test_interval_union_issubset_not():
    iu = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    interval = Interval(12, 14)
    assert not iu.issubset(interval)
    assert not interval.issubset(iu)
Esempio n. 10
0
def test_interval_union_simplification_overlap_connected():
    iu = IntervalUnion([[0, 3], [1, 1337]])
    iu._simplify()
    assert iu.intervals == [Interval(0, 1337)]
Esempio n. 11
0
def test_interval_union_intersection():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = IntervalUnion([[-1, 60]])
    iu3 = iu1.intersection(iu2)
    expected_intervals = [Interval(0, 10), Interval(20, 30), Interval(40, 50)]
    assert iu3.intervals == expected_intervals
Esempio n. 12
0
def test_interval_union_repr():
    iu1 = IntervalUnion([[0, 1], [2, 3]])
    assert repr(iu1) == "IntervalUnion([Interval(0, 1), Interval(2, 3)])"
Esempio n. 13
0
def test_interval_union_is_empty():
    iu = IntervalUnion([[], [], []])
    assert iu.is_empty()
Esempio n. 14
0
def test_interval_union_creation():
    with pytest.raises(TypeError) as exinfo:
        IntervalUnion("Foobar")
    assert str(exinfo.value) == "'<class 'str'>' is not a list"
Esempio n. 15
0
def test_interval_union_union_error():
    iu1 = IntervalUnion([[0, 1], [2, 3], [4, 5]])
    iu2 = [[-2, -1], [3.5, 3.7]]
    with pytest.raises(RuntimeError) as exinfo:
        iu1.union(iu2)
    assert str(exinfo.value) == "Union with type=<class 'list'> not supported"
Esempio n. 16
0
def test_interval_union_simplification_empty():
    iu = IntervalUnion([])
    iu._simplify()
    assert iu.intervals == []
Esempio n. 17
0
def test_interval_union_union_1():
    iu1 = IntervalUnion([[0, 1], [2, 3], [4, 5]])
    iu2 = IntervalUnion([[1, 2], [3, 4]])
    iu3 = iu1.union(iu2)
    assert iu3.intervals == [Interval(0, 5)]
Esempio n. 18
0
def test_interval_union_simplification_three_step_connected():
    iu = IntervalUnion([[0, 1], [2, 3], [4, 5], [1, 1337]])
    iu._simplify()
    assert iu.intervals == [Interval(0, 1337)]
Esempio n. 19
0
def test_interval_union_inequality():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = [[0, 10], [20, 30], [40, 50]]
    assert iu1 != iu2
Esempio n. 20
0
def test_interval_union_interval_unition():
    i01 = Interval(0, 1)
    iu = IntervalUnion([[4, 5], [6, 7]])
    iu_expected = IntervalUnion([[0, 1], [4, 5], [6, 7]])
    assert i01.union(iu) == iu_expected
    assert i01 | iu == iu_expected
Esempio n. 21
0
def test_interval_union_equality():
    iu1 = IntervalUnion([[0, 10]])
    iu2 = Interval(0, 10)
    assert iu1 == iu2
Esempio n. 22
0
def test_interval_union_intersection_3():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = IntervalUnion([[10, 20]])
    iu3 = iu1.intersection(iu2)
    assert iu3.intervals == [Interval(10, 10), Interval(20, 20)]
Esempio n. 23
0
def test_interval_union_str():
    iu1 = IntervalUnion([[0, 1], [2, 3]])
    assert str(iu1) == "[Interval(0, 1), Interval(2, 3)]"
Esempio n. 24
0
def test_interval_union_simplification_disjoint():
    iu = IntervalUnion([[0, 1], [42, 1337]])
    iu._simplify()
    assert iu.intervals == [Interval(0, 1), Interval(42, 1337)]
Esempio n. 25
0
def test_interval_intersection_non_interval():
    i1 = Interval(0, 10)
    iu1 = IntervalUnion([[0, 1], [2, 3]])
    i1.intersection(iu1) == iu1
Esempio n. 26
0
def test_interval_union_intersection_2():
    iu1 = IntervalUnion([[0, 10], [20, 30], [40, 50]])
    iu2 = IntervalUnion([[5, 25], [45, 60]])
    iu3 = iu1.intersection(iu2)
    iu_expected = [Interval(5, 10), Interval(20, 25), Interval(45, 50)]
    assert iu3.intervals == iu_expected