예제 #1
0
    def test_corners_and_dimensions_correctly_calculated(self):
        for corner1, corner2 in self.RECT_CORNER_TEST_CASES:
            # Arrange
            rect = Rectangle(corner1, corner2)

            x1 = min(corner1.x, corner2.x)
            x2 = max(corner1.x, corner2.x)
            y1 = min(corner1.y, corner2.y)
            y2 = max(corner1.y, corner2.y)
            width = x2 - x1
            height = y2 - y1

            # Check dimensions
            self.assertEquals(rect.width(), width)
            self.assertEquals(rect.height(), height)
            self.assertEquals(rect.area(), width * height)

            # Test that all corners are correct
            self.assertEqual(rect.top_left().x, x1)
            self.assertEquals(rect.top_left().y, y1)
            self.assertEquals(rect.bottom_left().x, x1)
            self.assertEquals(rect.bottom_left().y, y2)
            self.assertEquals(rect.top_right().x, x2)
            self.assertEquals(rect.top_right().y, y1)
            self.assertEquals(rect.bottom_right().x, x2)
            self.assertEquals(rect.bottom_right().y, y2)
예제 #2
0
 def test_zero_area_square_can_exist(self):
     rec = Rectangle(Point(0, 0), Point(0, 0))
     self.failUnlessEqual(0.0, rec.area())