def testMethodCheckIntersectionNegative(self): """ Returns false for intersecting rectangles """ intersector = Intersector() rectangle1 = Rectangle().getCoordinates() rectangle2 = Rectangle((10, 10), (10, 11), (11, 10), (11, 11)).getCoordinates() corners1 = intersector.findCorners(rectangle1) corners2 = intersector.findCorners(rectangle2) self.assertEqual(intersector.checkIntersection(corners1, corners2), False)
def testMethodCheckIntersectionPositive(self): """ Returns true for intersecting rectangles """ intersector = Intersector() rectangle1 = Rectangle().getCoordinates() rectangle2 = Rectangle((0.5, 0.5), (0.5, 1.5), (1.5, 0.5), (1.5, 1.5)).getCoordinates() corners1 = intersector.findCorners(rectangle1) corners2 = intersector.findCorners(rectangle2) self.assertEqual(intersector.checkIntersection(corners1, corners2), True)
def testMethodFindBottomLeftCorner(self): """ Finds the bottom left corner for a given rectangle """ intersector = Intersector() rectangle = Rectangle().getCoordinates() self.assertEqual(intersector.findBottomLeftCorner(rectangle), (0, 0))
def testMethodFindCorners(self): """ Finds the bottom left and top right corner for a given rectangle """ intersector = Intersector() rectangle = Rectangle().getCoordinates() self.assertEqual(intersector.findCorners(rectangle), [0, 0, 1, 1])
def testMethodFindTopRightCorner(self): """ Finds the top right corner for a given rectangle """ intersector = Intersector() rectangle = Rectangle().getCoordinates() self.assertEqual(intersector.findTopRightCorner(rectangle), (1, 1))
def testMethodGetCoordinatesError(self): """ Raises an error if one of the values is not a tuple """ p1 = (5,5) p2 = 1 p3 = (5,1) p4 = (0,0) self.assertRaises(ValueError, lambda: Rectangle(p1,p2,p3,p4).getCoordinates())
def testMethodGetCoordinatesWithFloats(self): """ Returns the coordinates in tuple form with float inputs """ p1 = (-1,-1) p2 = (-1.5,0) p3= (4,0) p4= (8.5,2) rectangle = Rectangle(p1,p2,p3,p4).getCoordinates() self.assertEqual(rectangle, (p1,p2,p3,p4))
def testInstantiation(self): """ Initialize the rectangle with four point values """ rectangle = Rectangle() self.assertIsInstance(rectangle, Rectangle) self.assertEqual(rectangle.p1, (0,0)) self.assertEqual(rectangle.p2, (0,1)) self.assertEqual(rectangle.p3, (1,0)) self.assertEqual(rectangle.p4, (1,1))
def testMethodGetCoordinatesWithNegatives(self): """ Returns the coordinates with negative inputs """ p1 = (-1,-1) p2 = (-1,0) p3 = (4,0) p4 = (8,2) rectangle = Rectangle(p1,p2,p3,p4).getCoordinates() self.assertEqual(rectangle, (p1,p2,p3,p4))
def testMethodGetCoordinates(self): """ Returns the coordinates in tuple form """ p1 = (5,5) p2 = (1,5) p3 = (5,1) p4 = (0,0) rectangle = Rectangle(p1,p2,p3,p4).getCoordinates() self.assertEqual(rectangle, (p1,p2,p3,p4))
def testMethodGetCoordinatesWithDefaults(self): """ Returns the default coordinates in tuple form """ rectangle = Rectangle().getCoordinates() self.assertEqual(rectangle, ((0,0),(0,1),(1,0),(1,1)))