Пример #1
0
def test_empty():
    assert i.open(1, 1).empty()
    assert i.open(3, 3).empty()
    assert i.openclosed(3, 3).empty()
    assert i.closedopen(3, 3).empty()
    assert not i.open(3, 4).empty()
    assert not i.openclosed(3, 4).empty()
Пример #2
0
def test_overlaps_corner_case_open():
    one = i.open(1, 5)
    two = i.open(5, 10)
    assert not one.overlaps(two)
    assert not two.overlaps(one)
    assert one.overlaps(one)
    assert two.overlaps(two)
Пример #3
0
def test_overlaps_false():
    one = i.open(1, 5)
    two = i.open(7, 12)
    assert not one.overlaps(two)
    assert not two.overlaps(one)
    assert one.overlaps(one)
    assert two.overlaps(two)
Пример #4
0
def test_overlaps_open():
    one = i.open(1, 5)
    two = i.open(3, 10)
    assert one.overlaps(two)
    assert two.overlaps(one)
    assert one.overlaps(one)
    assert two.overlaps(two)
Пример #5
0
def test_contains_self_open():
    small = i.open(1, 5)
    medium = i.open(3, 10)
    assert small in small
    assert small not in medium
    assert medium not in small
    assert medium in medium
Пример #6
0
def test_subtract_overlapping():
    left = IntervalSet((i.open(1, 4), i.open(5, 10)))
    right = IntervalSet((i.open(0, 2), i.open(6, 8)))
    expected = IntervalSet((
        i.closedopen(2, 4),
        i.openclosed(5, 6),
        i.closedopen(8, 10),
    ))
    assert left - right == expected
Пример #7
0
def test_complement():
    one = i.open(3, 6)
    two = i.open(7, 10)
    intervals = IntervalSet([one, two])
    complement = intervals.complement()
    (lower, middle, upper) = sorted(complement)  # an IntervalSet is not sorted

    assert lower == i.openclosed(i.NEGATIVE_INFINITY, 3)
    assert middle == i.closed(6, 7)
    assert upper == i.closedopen(10, i.INFINITY)
Пример #8
0
def test_values_in():
    one = i.open(1, 5)
    two = i.closed(7, 10)
    ivset = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    assert 1 not in ivset
    assert 1.00000001 in ivset
    assert 3 in ivset
    assert 7 in ivset
    assert 8 in ivset
    assert 10.0001 not in ivset
    assert one in ivset
    assert two in ivset
Пример #9
0
def test_non_equality():
    small, medium = get_intervals()[:2]
    assert small != medium
    assert small != i.openclosed(1,5)
    assert small != i.closedopen(1,5)
    assert small != i.closed(1,5)
    assert small != i.Interval(i.Interval.OPEN, 1, 7, i.Interval.OPEN)
    assert small != i.open(100, 288)
Пример #10
0
def test_open_interval_construction_using_helper():
    expected_lower = i.Interval.OPEN
    expectedlower_value = 10
    expected_upper_value = 100
    expected_upper = i.Interval.OPEN
    result = i.open(10, 100)
    assert result.lower == expected_lower
    assert result.lower_value == expectedlower_value
    assert result.upper_value == expected_upper_value
    assert result.upper == expected_upper
Пример #11
0
def test_overlaps_empty():
    assert not i.open(0, 0).overlaps(i.closed(1, 20))
    assert not i.open(1, 1).overlaps(i.closed(1, 20))
    assert not i.open(2, 2).overlaps(i.closed(1, 20))
    assert not i.closed(1, 20).overlaps(i.open(0, 0))
    assert not i.closed(1, 20).overlaps(i.open(1, 1))
    assert not i.closed(1, 20).overlaps(i.open(2, 2))
Пример #12
0
def test_overlaps_does_not_change_intervals():
    one = i.open(3, 6)
    two = i.open(1, 4)
    assert one.overlaps(two)
    assert one == i.open(3, 6)
    assert two == i.open(1, 4)
    assert two.overlaps(one)
    assert one == i.open(3, 6)
    assert two == i.open(1, 4)
Пример #13
0
def test_intersection_of_equal():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    result = first.intersection(first)
    assert result == first
Пример #14
0
def test_intersect_non_overlapping():
    one = i.open(3, 6)
    two = i.open(8, 10)
    expected = None
    assert one.intersect(two) == expected
    assert two.intersect(one) == expected
Пример #15
0
def test_add_already_contained_has_no_effect():
    expected = IntervalSet((i.open(1, 7), ))
    result = IntervalSet((i.open(1, 7), ))
    result.add(i.open(2, 4))
    assert result == expected
Пример #16
0
def test_equality_of_not_equal():
    one = IntervalSet([i.open(1, 10)])
    two = IntervalSet([i.closed(1, 10)])
    assert one != two
Пример #17
0
def test_union_via_overloaded_or():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(3, 10)
    assert one | two == expected
    assert two | one == expected
Пример #18
0
def test_subtract_overlapping_end():
    left = i.open(1, 10)
    right = i.open(5, 10)
    expected = i.openclosed(1, 5)
    assert left - right == expected
Пример #19
0
def test_union_non_overlapping():
    one = i.open(3, 6)
    two = i.open(8, 10)
    expected = IntervalSet([one, two])
    assert one.union(two) == expected
    assert two.union(one) == expected
Пример #20
0
def test_subtract_overlapping_start():
    left = i.open(1, 10)
    right = i.open(1, 5)
    expected = i.closedopen(5, 10)
    assert left - right == expected
Пример #21
0
def test_replace():
    assert i.open(1, 4).replace(upper_value=5) == i.open(1, 5)
    assert i.open(1, 4).replace(upper=i.Interval.CLOSED) == i.openclosed(1, 4)
    assert i.open(1, 4).replace(lower=i.Interval.CLOSED) == i.closedopen(1, 4)
    assert i.open(1, 4).replace(lower_value=0) == i.open(0, 4)
Пример #22
0
def test_subtract_overlapping():
    left = i.open(3, 6)
    right = i.open(4, 8)
    expected = i.openclosed(3, 4)
    assert left - right == expected
Пример #23
0
def test_subtract_non_overlapping():
    left = i.open(3, 6)
    right = i.open(8, 10)
    expected = i.open(3, 6)
    assert left - right == expected
Пример #24
0
def test_union_via_overloaded_add():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(3, 10)
    assert one + two == expected
    assert two + one == expected
Пример #25
0
def test_intersect_non_overlapping():
    one = i.open(3, 6)
    two = i.open(8, 10)
    expected = None
    assert one.intersect(two) == expected
    assert two.intersect(one) == expected
Пример #26
0
def test_subtract_contained():
    left = i.open(3, 6)
    right = i.open(4, 5)
    expected = IntervalSet([i.openclosed(3, 4), i.closedopen(5, 6)])
    assert left - right == expected
Пример #27
0
def test_intersection_via_overloaded_and():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(4, 6)
    assert one & two == expected
    assert two & one == expected
Пример #28
0
def test_subtract_almost_complete_overlap():
    left = i.closed(1, 2)
    right = i.open(1, 5)
    expected = i.closed(1, 1)
    assert left - right == expected
Пример #29
0
def test_length_of_unioned():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22,23)))
    # This is of length 3 as 2 of the intervals overlap and therefore join together
    assert len(first.union(second)) == 3
Пример #30
0
def test_subtract_empty_from_empty_is_empty():
    assert i.open(0, 0) - i.open(0, 0) == i.open(0, 0)
Пример #31
0
def test_intersection_of_disjoint_is_empty():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(20, 21), i.closed(22, 23)))
    expected = IntervalSet()
    result = first.intersection(second)
    assert result == expected
Пример #32
0
def test_overlaps():
    assert i.open(1, 4).overlaps(i.open(3, 6))
    assert i.open(3, 6).overlaps(i.open(1, 4))
    assert i.openclosed(1, 4).overlaps(i.open(3, 6))
Пример #33
0
def test_raises_exception_if_lower_is_larger_than_upper_value():
    with pytest.raises(ValueError):
        i.open(2, 1)
Пример #34
0
def test_creation():
    one = i.open(3, 6)
    two = i.open(7, 10)
    expected_data = set([one, two])
    result = IntervalSet([one, two])
    assert result._data == expected_data
Пример #35
0
def test_intersect_identical():
    one = i.open(3, 6)
    expected = one
    assert one.intersect(one) == expected
Пример #36
0
def test_overlaps_touching():
    assert not i.openclosed(1, 4).overlaps(i.openclosed(4, 5))
    assert not i.closedopen(1, 4).overlaps(i.closedopen(4, 5))
    assert not i.open(1, 4).overlaps(i.open(4, 5))
    assert i.closed(1, 4).overlaps(i.closed(4, 5))
Пример #37
0
def test_complement_empty():
    empty = i.open(0, 0)
    (interval, ) = empty.complement()
    assert interval == i.open(i.NEGATIVE_INFINITY, i.INFINITY)
Пример #38
0
def test_intersection_of_almost_overlapping():
    first = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    second = IntervalSet((i.open(1, 5), i.closed(7, 23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    result = first.intersection(second)
    assert result == expected
Пример #39
0
def test_overlaps():
    assert i.open(1, 4).overlaps(i.open(3, 6))
    assert i.open(3, 6).overlaps(i.open(1, 4))
    assert i.openclosed(1, 4).overlaps(i.open(3, 6))
Пример #40
0
def test_complement_whole():
    whole = i.open(i.NEGATIVE_INFINITY, i.INFINITY)
    assert whole.complement().empty()
Пример #41
0
def test_repr():
    assert repr(i.open(1, 2)) == '(1, 2)'
    assert repr(i.openclosed(1, 2)) == '(1, 2]'
    assert repr(i.closed(1, 2)) == '[1, 2]'
    assert repr(i.closedopen(1, 2)) == '[1, 2)'
Пример #42
0
def test_overlaps_touching():
    assert not i.openclosed(1, 4).overlaps(i.openclosed(4, 5))
    assert not i.closedopen(1, 4).overlaps(i.closedopen(4, 5))
    assert not i.open(1, 4).overlaps(i.open(4, 5))
    assert i.closed(1, 4).overlaps(i.closed(4, 5))
Пример #43
0
def test_interval_copy():
    assert i.open(1, 4).copy() == i.open(1, 4)
    assert i.openclosed(1, 4).copy() == i.openclosed(1, 4)
    assert i.closedopen(1, 4).copy() == i.closedopen(1, 4)
    assert i.closed(1, 4).copy() == i.closed(1, 4)
Пример #44
0
def test_creation():
    one = i.open(3, 6)
    two = i.open(7, 10)
    expected_data = set([one, two])
    result = IntervalSet([one, two])
    assert result._data == expected_data
Пример #45
0
def test_intersect_identical():
    one = i.open(3, 6)
    expected = one
    assert one.intersect(one) == expected
Пример #46
0
def test_intersection_of_almost_overlapping():
    first = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    second = IntervalSet((i.open(1, 5), i.closed(7,23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 10)))
    result = first.intersection(second)
    assert result == expected
Пример #47
0
def test_union_overlapping():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(3, 10)
    assert one.union(two) == expected
    assert two.union(one) == expected
Пример #48
0
def test_union_of_disjoint():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(12, 21), i.closed(22,23)))
    expected = IntervalSet((i.open(1, 5), i.closed(7, 10), i.open(12, 21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
Пример #49
0
def test_len_works_as_expected():
    assert len(IntervalSet((i.open(1, 5), i.closed(7, 10)))) == 2
Пример #50
0
def test_repr():
    interval_set = IntervalSet([i.open(3, 6), i.open(7, 10)])
    assert repr(interval_set) == 'IntervalSet((3, 6), (7, 10))'
Пример #51
0
def test_equality_of_two_equal_instances():
    one = IntervalSet([i.open(1, 10)])
    two = IntervalSet([i.open(1, 10)])
    assert one == two
Пример #52
0
def test_union_identical():
    one = i.open(3, 6)
    expected = one
    assert one.union(one) == expected
Пример #53
0
def test_interval_copy():
    assert i.open(1, 4).copy() == i.open(1, 4)
    assert i.openclosed(1, 4).copy() == i.openclosed(1, 4)
    assert i.closedopen(1, 4).copy() == i.closedopen(1, 4)
    assert i.closed(1, 4).copy() == i.closed(1, 4)
Пример #54
0
def test_equality_of_not_equal():
    one = IntervalSet([i.open(1, 10)])
    two = IntervalSet([i.closed(1, 10)])
    assert one != two
Пример #55
0
def test_intersection_of_disjoint_is_empty():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(20,21), i.closed(22,23)))
    expected = IntervalSet()
    result = first.intersection(second)
    assert result == expected
Пример #56
0
def test_intersection_via_overloaded_and():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(4, 6)
    assert one & two == expected
    assert two & one == expected
Пример #57
0
def test_union_of_overlapping():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    second = IntervalSet((i.open(8, 21), i.closed(22,23)))
    expected = IntervalSet((i.open(1, 5), i.closedopen(7, 21), i.closed(22, 23)))
    result = first.union(second)
    assert result == expected
Пример #58
0
def test_union_overlapping():
    one = i.open(3, 6)
    two = i.open(4, 10)
    expected = i.open(3, 10)
    assert one.union(two) == expected
    assert two.union(one) == expected
Пример #59
0
def test_union_of_equal():
    first = IntervalSet((i.open(1, 5), i.closed(7, 10)))
    result = first.union(first)
    assert result == first
Пример #60
0
def test_union_non_overlapping():
    one = i.open(3, 6)
    two = i.open(8, 10)
    expected = IntervalSet([one, two])
    assert one.union(two) == expected
    assert two.union(one) == expected