예제 #1
0
    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")
예제 #2
0
    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)