Пример #1
0
 def test_sets(self):
     x = Rectangle()
     self.assertEqual(x, Rectangle(0, 0, 0, 0))
     x.set(256, 256, 512, 512)
     self.assertEqual(x, Rectangle(256, 256, 512, 512))
     x.set_empty()
     self.assertEqual(x, Rectangle())
Пример #2
0
 def test_operator_not_eq(self):
     x = Rectangle(35, 150, 10, 25)
     y = Rectangle(35, 150, 10, 25)
     z = Rectangle(98, 999, 6, 3)
     self.assertFalse(x != y)
     self.assertFalse(x is y)
     self.assertTrue(x != z)
Пример #3
0
 def test_is_null(self):
     none = Rectangle()
     some = Rectangle(35, 50, 135, 150)
     null = Rectangle(35, 35, 35, 35)
     self.assertTrue(none.is_null())
     self.assertFalse(some.is_null())
     self.assertFalse(null.is_null())
Пример #4
0
 def test_operator_sub_eq(self):
     x = Rectangle(100, 235, 200, 335)
     x -= Point(35, 65)
     self.assertEqual(x, Rectangle(65, 170, 165, 270))
     x = Rectangle(100, 235, 200, 335)
     x -= Rectangle(1, 2, 3, 4)
     self.assertEqual(x, Rectangle(99, 233, 197, 331))
Пример #5
0
    def test_inflates(self):
        rc = Rectangle(0, 0, 300, 300)
        rc.inflate(50, 200)
        self.assertEqual(rc, Rectangle(-50, -200, 350, 500))

        rc = Rectangle(0, 0, 300, 300)
        rc.inflate_rect(Rectangle(50, 60, 300, 310))
        self.assertEqual(rc, Rectangle(-50, -60, 600, 610))
Пример #6
0
    def test_operator_add_eq(self):
        x = Rectangle(100, 235, 200, 335)
        x += Point(35, 65)
        self.assertEqual(x, Rectangle(135, 300, 235, 400))

        x = Rectangle(100, 235, 200, 335)
        x += Rectangle(1, 2, 3, 4)
        self.assertEqual(x, Rectangle(101, 237, 203, 339))
Пример #7
0
    def test_deflates(self):
        rc = Rectangle(10, 10, 50, 50)
        rc.deflate(1, 2)
        self.assertEqual(rc, Rectangle(11, 12, 49, 48))

        rc = Rectangle(10, 10, 50, 50)
        rc.deflate_rect(Rectangle(1, 2, 3, 4))
        self.assertEqual(rc, Rectangle(11, 12, 47, 46))
Пример #8
0
    def test_normalize(self):
        x = Rectangle(110, 100, 250, 310)
        x.normalize()
        y = Rectangle(250, 310, 110, 100)
        y.normalize()
        self.assertEqual(x, y)

        x = Rectangle(0, 0, 100, 100)
        x.normalize()
        self.assertEqual(x, Rectangle(0, 0, 100, 100))
Пример #9
0
    def test_operator_add(self):
        x = Rectangle(100, 235, 200, 335)
        y = x + Point(35, 65)
        self.assertEqual(y, Rectangle(135, 300, 235, 400))

        x = Rectangle(100, 235, 200, 335)
        y = x + Rectangle(1, 2, 3, 4)
        self.assertEqual(y, Rectangle(101, 237, 203, 339))

        self.assertRaises(TypeError, lambda: x + (1, 1))
Пример #10
0
    def test_operator_sub(self):
        x = Rectangle(100, 235, 200, 335)
        y = x - Point(35, 65)
        self.assertEqual(y, Rectangle(65, 170, 165, 270))

        x = Rectangle(100, 235, 200, 335)
        y = x - Rectangle(1, 2, 3, 4)
        self.assertEqual(y, Rectangle(99, 233, 197, 331))

        self.assertRaises(TypeError, lambda: x - 13)
Пример #11
0
    def test_constructor(self):
        rc = Rectangle()
        self.assertEqual(rc.left, 0)
        self.assertEqual(rc.top, 0)
        self.assertEqual(rc.right, 0)
        self.assertEqual(rc.bottom, 0)

        rc = Rectangle(top=10, bottom=100, right=128, left=16)
        self.assertEqual(rc.left, 16)
        self.assertEqual(rc.top, 10)
        self.assertEqual(rc.right, 128)
        self.assertEqual(rc.bottom, 100)
Пример #12
0
 def test_intersect(self):
     rc = Rectangle(125, 0, 150, 200)
     result = rc.intersect(Rectangle(0, 75, 350, 95))
     self.assertEqual(result, Rectangle(125, 75, 150, 95))
Пример #13
0
 def test_size(self):
     x = Rectangle(10, 10, 50, 50)
     sz = x.size()
     self.assertTrue(isinstance(sz, Size))
     self.assertEqual(sz, Size(40, 40))
Пример #14
0
 def test_move_to_y(self):
     rc = Rectangle(0, 0, 100, 100)
     rc.move_to_y(20)
     self.assertEqual(rc, Rectangle(0, 20, 100, 120))
Пример #15
0
 def test_move_to_x(self):
     rc = Rectangle(0, 0, 100, 100)
     rc.move_to_x(10)
     self.assertEqual(rc, Rectangle(10, 0, 110, 100))
Пример #16
0
 def test_offset(self):
     x = Rectangle(0, 0, 35, 35)
     x.offset(230, 230)
     self.assertEqual(x, Rectangle(230, 230, 265, 265))
Пример #17
0
 def test_width(self):
     x = Rectangle(20, 30, 80, 70)
     self.assertEqual(x.width(), 60)
Пример #18
0
 def test_operator_assign(self):
     x = Rectangle(0, 0, 127, 128)
     y = x
     self.assertEqual(y, Rectangle(0, 0, 127, 128))
Пример #19
0
 def test_pt_in_rect(self):
     x = Rectangle(5, 5, 100, 100)
     self.assertTrue(x.pt_in_rect(Point(35, 50)))
     self.assertFalse(x.pt_in_rect(Point(125, 298)))
Пример #20
0
 def test_center_point(self):
     rc = Rectangle(210, 150, 350, 900)
     pt = rc.center_point()
     self.assertTrue(isinstance(pt, Point))
     self.assertEqual(pt, Point(280, 525))
Пример #21
0
 def test_bottom_right(self):
     rc = Rectangle(210, 150, 350, 900)
     pt = rc.bottom_right()
     self.assertTrue(isinstance(pt, Point))
     self.assertEqual(pt, Point(350, 900))
Пример #22
0
 def test_top_left(self):
     x = Rectangle(128, 128, 256, 256)
     pt = x.top_left()
     self.assertTrue(isinstance(pt, Point))
     self.assertEqual(pt, Point(128, 128))
Пример #23
0
 def test_union(self):
     x = Rectangle(100, 0, 200, 300)
     y = Rectangle(0, 100, 300, 200)
     z = x.union(y)
     self.assertEqual(z, Rectangle(0, 0, 300, 300))
Пример #24
0
 def test_height_and_width(self):
     rc = Rectangle(20, 30, 80, 70)
     self.assertEqual(rc.height(), 40)
     self.assertEqual(rc.width(), 60)