예제 #1
0
def test_reversal():
    for _ in range(1000):
        a = u.get_rand_range_part()
        b = u.get_rand_range_part()

        if a < b:
            assert b > a
        elif b < a:
            assert a > b
        else:
            assert a == b
예제 #2
0
def test_super_sub_range_exclusive():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(x, y)
        assert other.is_super_range(part) and part.is_sub_range(other)
        assert other > part and part < other and part != other
예제 #3
0
def test_no_overlap():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_above_exclusive(part.b)
        y = u.get_rand_int_above_exclusive(x)
        other = RangePart(x, y)
        diff = [part, other] if part < other else [other, part]
        assert part - other == other - part == diff
예제 #4
0
def test_left_overlap_on_bounds():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        other = RangePart(x, part.a)
        assert part.left_overlap_with(other)
        assert other.a < part.a == other.b < part.b
        assert part - other == other - part == [other, part]
예제 #5
0
def test_is_super_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_in_range(part.a, part.b - 1)
        y = u.get_rand_int_in_range(x + 1, part.b)
        other = RangePart(x, y)
        assert part.is_super_range(other)
        assert other.is_sub_range(part)
예제 #6
0
def test_right_overlap_in_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_in_range(part.a, part.b)
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(x, y)
        assert part.a < other.a < part.b < other.b
        assert part.right_overlap_with(other) and other.left_overlap_with(part)
예제 #7
0
def test_left_overlap_out_of_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        y = u.get_rand_int_in_range_exclusive(part.a, part.b)
        x = u.get_rand_int_below_exclusive(part.a)
        other = RangePart(x, y)
        assert other.a < part.a < other.b < part.b
        assert part.left_overlap_with(other) and other.right_overlap_with(part)
예제 #8
0
def test_add_same_right_bound():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.b)
        other = RangePart(x, part.b)
        sum_a = min(part.a, other.a)
        assert other + part == part + other == RangePart(
            sum_a, part.b) == RangePart(sum_a, other.b)
예제 #9
0
def test_add_same_left_bound():
    for _ in range(1000):
        part = u.get_rand_range_part()
        y = u.get_rand_int_above_exclusive(part.a)
        other = RangePart(part.a, y)
        sum_b = max(part.b, other.b)
        assert other + part == part + other == RangePart(
            part.a, sum_b) == RangePart(other.a, sum_b)
예제 #10
0
def test_right_overlap_on_bounds():
    for _ in range(1000):
        part = u.get_rand_range_part()
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(part.b, y)
        diff = [part, other]
        assert part.right_overlap_with(other)
        assert part.a < other.a == part.b < other.b
        assert part - other == other - part == diff
예제 #11
0
def test_no_overlap():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_above_exclusive(part.b)
        y = u.get_rand_int_above_exclusive(x)
        other = RangePart(x, y)
        assert not other.right_overlap_with(
            part) and not other.left_overlap_with(part)
        assert other > part and part < other and part != other
예제 #12
0
def test_add_super_range():
    for _ in range(1000):
        parent = u.get_rand_range_part()
        x = u.get_rand_int_in_range(parent.a, parent.b - 1)
        y = u.get_rand_int_in_range(x, parent.b)
        child = RangePart(x, y)

        assert parent.a < child.a < child.b < parent.b
        assert child + parent == parent + child == parent
예제 #13
0
def test_add_overlap_exclusive():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        y = u.get_rand_int_in_range(part.a, part.b - 1)
        other = RangePart(x, y)

        assert other.a < part.a < other.b < part.b
        assert other + part == part + other == RangePart(other.a, part.b)
예제 #14
0
def test_right_overlap_in_bounds():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_in_range_exclusive(part.a, part.b)
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(x, y)
        diff = [RangePart(part.a, other.a), RangePart(part.b, other.b)]
        assert part.right_overlap_with(other)
        assert part.a < other.a < part.b < other.b
        assert part - other == other - part == diff
예제 #15
0
def test_super_sub_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(x, y)
        diff = [RangePart(other.a, part.a), RangePart(part.b, other.b)]
        assert other.a < part.a < part.b < other.b
        assert other.is_super_range(part)
        assert part.is_sub_range(other)
        assert part - other == other - part == diff
예제 #16
0
def test_transitivity():
    for _ in range(1000):
        a = u.get_rand_range_part()
        b = u.get_rand_range_part()
        c = u.get_rand_range_part()

        if a < b and b < c:
            assert a < c
        elif b < c and c < a:
            assert b < c
        elif c < b and b < a:
            assert c < a
        elif a < c and c < b:
            assert a < b
        elif c < a and a < b:
            assert c < b
        elif b < a and a < c:
            assert b < c
        else:
            assert False, (a < b, a < c, b < c, c < b, c < a, b < a)
예제 #17
0
def test_left_overlap_in_bounds():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        y = u.get_rand_int_in_range_exclusive(part.a, part.b)
        other = RangePart(x, y)
        assert part.left_overlap_with(other)
        assert other.a < part.a < other.b < part.b
        assert part - other == other - part == [
            RangePart(other.a, part.a),
            RangePart(other.b, part.b)
        ]
예제 #18
0
def test_below_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        item = u.get_rand_int_below_exclusive(part.a)
        assert item not in part
예제 #19
0
def test_commutative():
    for _ in range(1000):
        a = u.get_rand_range_part()
        b = u.get_rand_range_part()
        assert a + b == b + a
예제 #20
0
def test_from_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        item = u.get_rand_int_in_range(part.a, part.b)
        assert item in part
예제 #21
0
def test_inequality():  # TODO fix me
    for _ in range(1000):
        a = u.get_rand_range_part()
        b = RangePart(*u.get_rand_pair())
        assert a != b
        assert hash(a) != hash(b)
예제 #22
0
def test_copy():
    for _ in range(1000):
        part = u.get_rand_range_part()
        assert part == copy.copy(part)
예제 #23
0
def test_associative():
    for _ in range(1000):
        a = u.get_rand_range_part()
        b = u.get_rand_range_part()
        c = u.get_rand_range_part()
        assert (a + b) + c == a + (b + c)
예제 #24
0
def test_sub_range_self():
    for _ in range(1000):
        part = u.get_rand_range_part()
        assert part.is_sub_range(part)
예제 #25
0
def test_same_left_bound_right_bound_out_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        y = u.get_rand_int_above_exclusive(part.b)
        other = RangePart(part.a, y)
        assert other > part and part < other and other != part
예제 #26
0
def test_same_left_bound_right_bound_in_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        y = u.get_rand_int_in_range_exclusive(part.a, part.b)
        other = RangePart(part.a, y)
        assert part > other and other < part and part != other
예제 #27
0
def test_same_right_bound_left_bound_out_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_below_exclusive(part.a)
        other = RangePart(x, part.b)
        assert part > other and other < part and other != part
예제 #28
0
def test_same_right_bound_left_bound_in_range():
    for _ in range(1000):
        part = u.get_rand_range_part()
        x = u.get_rand_int_in_range_exclusive(part.a, part.b)
        other = RangePart(x, part.b)
        assert other > part and part < other and part != other
예제 #29
0
def test_sub_self():
    for _ in range(1000):
        part = u.get_rand_range_part()
        assert not part - part
예제 #30
0
def test_right_bound():
    for _ in range(1000):
        part = u.get_rand_range_part()
        assert part.b in part