def test_add_no_overlap(): for _ in range(1000): part = u.get_rand_range_part() y = u.get_rand_int_below_exclusive(part.a) x = u.get_rand_int_below_exclusive(y) other = RangePart(x, y) assert other.a < other.b < part.a < part.b assert other + part == part + other == RangePart(other.a, part.b)
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_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_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_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_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_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_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