Skip to content

Commit 983e1a2

Browse files
authored
Merge pull request #334 from alanwuha/master
substitute tests with doctest in composite.py
2 parents f38a8d2 + 19ef916 commit 983e1a2

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

patterns/structural/composite.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,34 @@ def render(self):
5555
print("Ellipse: {}".format(self.name))
5656

5757

58-
if __name__ == '__main__':
59-
ellipse1 = Ellipse("1")
60-
ellipse2 = Ellipse("2")
61-
ellipse3 = Ellipse("3")
62-
ellipse4 = Ellipse("4")
58+
def main():
59+
"""
60+
>>> ellipse1 = Ellipse("1")
61+
>>> ellipse2 = Ellipse("2")
62+
>>> ellipse3 = Ellipse("3")
63+
>>> ellipse4 = Ellipse("4")
6364
64-
graphic1 = CompositeGraphic()
65-
graphic2 = CompositeGraphic()
65+
>>> graphic1 = CompositeGraphic()
66+
>>> graphic2 = CompositeGraphic()
6667
67-
graphic1.add(ellipse1)
68-
graphic1.add(ellipse2)
69-
graphic1.add(ellipse3)
70-
graphic2.add(ellipse4)
68+
>>> graphic1.add(ellipse1)
69+
>>> graphic1.add(ellipse2)
70+
>>> graphic1.add(ellipse3)
71+
>>> graphic2.add(ellipse4)
7172
72-
graphic = CompositeGraphic()
73+
>>> graphic = CompositeGraphic()
7374
74-
graphic.add(graphic1)
75-
graphic.add(graphic2)
75+
>>> graphic.add(graphic1)
76+
>>> graphic.add(graphic2)
7677
77-
graphic.render()
78+
>>> graphic.render()
79+
Ellipse: 1
80+
Ellipse: 2
81+
Ellipse: 3
82+
Ellipse: 4
83+
"""
7884

79-
### OUTPUT ###
80-
# Ellipse: 1
81-
# Ellipse: 2
82-
# Ellipse: 3
83-
# Ellipse: 4
85+
86+
if __name__ == "__main__":
87+
import doctest
88+
doctest.testmod()

0 commit comments

Comments
 (0)