コード例 #1
0
    def test_point(self):
        figure = {"type": "point", "x": 50, "y": 10, "color": "blue"}
        point = Point.build(figure)

        self.assertEqual(50, point.x)
        self.assertEqual(10, point.y)
        self.assertEqual("blue", point.color)

        figure = {"type": "point", "x": 50, "y": 10}
        point = Point.build(figure)

        self.assertEqual(None, point.color)

        figure = {"type": "point", "x": 50, "color": "blue"}
        self.assertRaises(ValueError, Point.build, figure)
コード例 #2
0
ファイル: parser.py プロジェクト: kriczq/shape-drawer
    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")