Esempio n. 1
0
 def test_operator_add(self):
     x = Point(100, 100)
     y = Point(35, 35)
     z = x + y
     self.assertEqual(z, Point(135, 135))
     self.assertEqual(x, Point(100, 100))
     self.assertEqual(y, Point(35, 35))
Esempio n. 2
0
 def test_operator_sub(self):
     x = Point(100, 100)
     y = Point(35, 35)
     z = x - y
     self.assertEqual(z, Point(65, 65))
     self.assertEqual(x, Point(100, 100))
     self.assertEqual(y, Point(35, 35))
Esempio n. 3
0
    def test_constructor(self):
        default = Point()
        self.assertEqual(default.x, 0)
        self.assertEqual(default.y, 0)

        default = Point(y=25, x=10)
        self.assertEqual(default.x, 10)
        self.assertEqual(default.y, 25)
Esempio n. 4
0
    def test_offset(self):
        x = Point(100, 100)
        x.offset(35, 35)
        self.assertEqual(x, Point(135, 135))

        x = Point(100, 100)
        x.offset(-25, -50)
        self.assertEqual(x, Point(75, 50))
Esempio n. 5
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))
Esempio n. 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))
Esempio n. 7
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)
Esempio n. 8
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))
Esempio n. 9
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))
Esempio n. 10
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))
Esempio n. 11
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)))
Esempio n. 12
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))
Esempio n. 13
0
 def test_operator_eq(self):
     x = Point(256, 128)
     y = Point(256, 128)
     self.assertTrue(x == y)
     self.assertFalse(x is y)
Esempio n. 14
0
 def test_manhattan_distance(self):
     x = Point(0, 0)
     self.assertEqual(x.manhattan_distance(Point(0, 0)), 0)
     self.assertEqual(x.manhattan_distance(Point(1, 1)), 2)
     self.assertEqual(x.manhattan_distance(Point(-3, -3)), 6)
Esempio n. 15
0
 def test_operator_neq(self):
     x = Point(256, 128)
     y = Point(1024, 4096)
     self.assertTrue(x != y)
Esempio n. 16
0
 def test_operator_add_eq(self):
     x = Point(100, 100)
     y = Point(35, 35)
     x += y
     self.assertEqual(x, Point(135, 135))
     self.assertEqual(y, Point(35, 35))
Esempio n. 17
0
 def test_operator_sub_eq(self):
     x = Point(100, 100)
     y = Point(35, 35)
     x -= y
     self.assertEqual(x, Point(65, 65))
     self.assertEqual(y, Point(35, 35))