def build_figure(figure): if figure["type"] == "point": return Point.build(figure) if figure["type"] == "circle": return Circle.build(figure) if figure["type"] == "polygon": return Polygon.build(figure) if figure["type"] == "rectangle": return Rectangle.build(figure) if figure["type"] == "square": return Square.build(figure) raise ValueError("incorrect type")
def test_square(self): figure = { "type": "square", "x": 50, "y": 10, "size": 10, "color": "blue" } square = Square.build(figure) self.assertEqual(50, square.x) self.assertEqual(10, square.y) self.assertEqual("blue", square.color) self.assertEqual(10, square.size) figure = {"type": "square", "x": 50, "y": 10} self.assertRaises(ValueError, Square.build, figure)