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)
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)
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
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)
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)
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)
def test_equality(): for _ in range(1000): x, y = u.get_rand_pair() a = RangePart(x, y) b = RangePart(x, y) # same object and same hashcode assert a == b assert hash(a) == hash(b)
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)
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
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
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
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) ]
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
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]
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
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
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
def test_invalid_constructor_equal(): for _ in range(1000): x = u.get_rand_int() with pt.raises(ValueError): RangePart(x, x)
def get_rand_range_part(): return RangePart(*get_rand_pair())
def test_invalid_constructor(): for _ in range(1000): x, y = u.get_rand_pair() with pt.raises(ValueError): RangePart(y, x)
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)
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
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
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