コード例 #1
0
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)

    with pytest.raises(ValueError):
        Rectangle.bounding_box([])
コード例 #2
0
def test_rectangle_bounding_box():
    r1 = Rectangle(Point(0, 1), Point(2, 3))
    r2 = Rectangle(Point(0, 0), Point(4, 2))

    assert Rectangle.bounding_box([r1,
                                   r2]) == Rectangle(Point(0, 0), Point(4, 3))