def test_rectangle_intersection(): r_large = Rectangle.from_list([0, 0, 5, 5]) r_small = Rectangle.from_list([1, 1, 2, 2]) r_touching = Rectangle.from_list([0, 0, 4, 5]) r_other = Rectangle.from_list([-3, -3, -1, -1]) assert Rectangle.intersection([r_other, r_touching]) == Rectangle.empty() assert Rectangle.intersection([r_large, r_small]) == r_small assert Rectangle.intersection([r_large, r_large]) == r_large int1 = Rectangle.intersection( [Rectangle.from_list([0, 0, 2, 2]), Rectangle.from_list([0, 2, 1, 3])]) assert int1 == Rectangle.from_list([0, 2, 1, 2]) assert int1 != Rectangle.empty() assert Rectangle.intersection([r_other, Rectangle.empty()]) == Rectangle.empty() with pytest.raises(ValueError): Rectangle.intersection([]) with pytest.raises(ValueError): Rectangle.intersection([Rectangle.empty()])
def test_rectangle_resized(): d = 3 r = Rectangle.from_list([1, 2, 6, 7]) R = r.resized(delta=d) assert R.area == 2 * d * (r.width + r.height + 2 * d) + r.area assert R.contains(r) assert Rectangle.intersection([R, r]) == r assert Rectangle.bounding_box([R, r]) == R with pytest.raises(AssertionError): _ = r.resized(delta=-6) assert r.resized(delta=-r.width / 2) == Rectangle(r.center, r.center)