def testValidateLine(self): l1 = ShapeFactory.build("line", Point(1, 1), Point(-1, -5)) Line.validateLine(l1, "Line unexpectedly invalid") self.assertRaises(ShapeException, Line.validateLine, "(1, 1, -1, -5)", "String \'(1, 1, -1, -5)\' is not a valid line") self.assertRaises(ShapeException, Line.validateLine, Point(1, 1), "Point is not a valid line")
def validateEllipse(value, errorMessage): if not isinstance(value, Ellipse): raise ShapeException(errorMessage) Line.validateLine(value.axis1, "Axis1 is not a valid line") Line.validateLine(value.axis2, "Axis2 is not a valid line") if value.computeArea() <= 0: raise ShapeException(errorMessage) Validator.validateLinesFormRightAngles([value.axis1, value.axis2], "Axis are not perpendicular")
def validateRectangle(value, errorMessage): if not isinstance(value, Rectangle): raise ShapeException(errorMessage) Line.validateLine(value.line1, "Line 1 is not a valid line.") Line.validateLine(value.line2, "Line 2 is not a valid line.") Line.validateLine(value.line3, "Line 3 is not a valid line.") Line.validateLine(value.line4, "Line 4 is not a valid line.") Validator.validateLinesFormLoop([value.line1, value.line2, value.line3, value.line4], "Lines do not form an enclosed rectangle.") Validator.validateLinesFormRightAngles([value.line1, value.line2, value.line3, value.line4], "Lines do not form 90 degree angles.")
def validateTriangle(value, errorMessage): if not isinstance(value, Triangle): raise ShapeException(errorMessage) Line.validateLine(value.line1, "Line 1 has is not a valid line.") Line.validateLine(value.line2, "Line 2 has is not a valid line.") Line.validateLine(value.line3, "Line 3 has is not a valid line.") Validator.validateSlopesAreDifferent( [value.line1, value.line2, value.line3], "Angles of lines form an invalid triangle") Validator.validateLinesFormLoop( [value.line1, value.line2, value.line3], "Lines do not form an enclosed triangle")