1
1
import unittest
2
2
3
- from graphics import Circle , Rectangle , Line
3
+ from graphics import Circle , Rectangle , Line , Arrow , Text
4
+
4
5
5
6
class TestCircle (unittest .TestCase ):
6
7
def test_init (self ):
7
- circle = Circle ((0 , 0 ), 3 , color = ' red' , filled = True )
8
- self .assertEqual (circle .type , ' circle' )
8
+ circle = Circle ((0 , 0 ), 3 , color = " red" , filled = True )
9
+ self .assertEqual (circle .type , " circle" )
9
10
self .assertEqual (circle .center , (0 , 0 ))
10
11
self .assertEqual (circle .radius , 3 )
11
- self .assertEqual (circle .kwargs , {' color' : ' red' , ' filled' : True })
12
+ self .assertEqual (circle .kwargs , {" color" : " red" , " filled" : True })
12
13
13
14
def test_center_as_float (self ):
14
- circle = Circle ((0.5 , 0.5 ), 3 , color = ' red' , filled = True )
15
+ circle = Circle ((0.5 , 0.5 ), 3 , color = " red" , filled = True )
15
16
self .assertEqual (circle .center , (0.5 , 0.5 ))
16
17
17
18
def test_negative_radius (self ):
18
- circle = Circle ((0 , 0 ), - 3 , color = ' red' , filled = True )
19
+ circle = Circle ((0 , 0 ), - 3 , color = " red" , filled = True )
19
20
self .assertEqual (circle .radius , - 3 )
20
21
21
22
def test_color_as_none (self ):
22
23
circle = Circle ((0 , 0 ), 3 , color = None , filled = True )
23
- self .assertEqual (circle .kwargs , {' color' : None , ' filled' : True })
24
+ self .assertEqual (circle .kwargs , {" color" : None , " filled" : True })
24
25
25
26
def test_additional_kwargs (self ):
26
- circle = Circle ((0 , 0 ), 3 , color = 'red' , filled = True , linewidth = 2 )
27
- self .assertEqual (circle .kwargs , {'color' : 'red' , 'filled' : True , 'linewidth' : 2 })
27
+ circle = Circle ((0 , 0 ), 3 , color = "red" , filled = True , linewidth = 2 )
28
+ self .assertEqual (
29
+ circle .kwargs , {"color" : "red" , "filled" : True , "linewidth" : 2 }
30
+ )
31
+
28
32
29
33
class TestRectangle (unittest .TestCase ):
30
34
def test_init (self ):
31
- rectangle = Rectangle ((0 , 0 ), (3 , 4 ), color = ' blue' , filled = False )
32
- self .assertEqual (rectangle .type , ' rectangle' )
35
+ rectangle = Rectangle ((0 , 0 ), (3 , 4 ), color = " blue" , filled = False )
36
+ self .assertEqual (rectangle .type , " rectangle" )
33
37
self .assertEqual (rectangle .top_left , (0 , 0 ))
34
38
self .assertEqual (rectangle .bottom_right , (3 , 4 ))
35
- self .assertEqual (rectangle .kwargs , {' color' : ' blue' , ' filled' : False })
39
+ self .assertEqual (rectangle .kwargs , {" color" : " blue" , " filled" : False })
36
40
37
41
def test_coordinates_as_float (self ):
38
- rectangle = Rectangle ((0.5 , 0.5 ), (3.5 , 4.5 ), color = ' blue' , filled = False )
42
+ rectangle = Rectangle ((0.5 , 0.5 ), (3.5 , 4.5 ), color = " blue" , filled = False )
39
43
self .assertEqual (rectangle .top_left , (0.5 , 0.5 ))
40
44
self .assertEqual (rectangle .bottom_right , (3.5 , 4.5 ))
41
45
42
46
def test_negative_coordinates (self ):
43
- rectangle = Rectangle ((- 1 , - 1 ), (- 2 , - 2 ), color = ' blue' , filled = False )
47
+ rectangle = Rectangle ((- 1 , - 1 ), (- 2 , - 2 ), color = " blue" , filled = False )
44
48
self .assertEqual (rectangle .top_left , (- 1 , - 1 ))
45
49
self .assertEqual (rectangle .bottom_right , (- 2 , - 2 ))
46
50
47
51
def test_color_as_none (self ):
48
52
rectangle = Rectangle ((0 , 0 ), (3 , 4 ), color = None , filled = False )
49
- self .assertEqual (rectangle .kwargs , {' color' : None , ' filled' : False })
53
+ self .assertEqual (rectangle .kwargs , {" color" : None , " filled" : False })
50
54
51
55
def test_additional_kwargs (self ):
52
- rectangle = Rectangle ((0 , 0 ), (3 , 4 ), color = 'blue' , filled = False , linewidth = 2 )
53
- self .assertEqual (rectangle .kwargs , {'color' : 'blue' , 'filled' : False , 'linewidth' : 2 })
56
+ rectangle = Rectangle ((0 , 0 ), (3 , 4 ), color = "blue" , filled = False , linewidth = 2 )
57
+ self .assertEqual (
58
+ rectangle .kwargs , {"color" : "blue" , "filled" : False , "linewidth" : 2 }
59
+ )
60
+
54
61
55
62
class TestLine (unittest .TestCase ):
56
63
def test_init (self ):
57
- line = Line ((0 , 0 ), (3 , 4 ), color = ' green' , dashed = True )
58
- self .assertEqual (line .type , ' line' )
64
+ line = Line ((0 , 0 ), (3 , 4 ), color = " green" , dashed = True )
65
+ self .assertEqual (line .type , " line" )
59
66
self .assertEqual (line .start , (0 , 0 ))
60
67
self .assertEqual (line .end , (3 , 4 ))
61
- self .assertEqual (line .kwargs , {' color' : ' green' , ' dashed' : True })
68
+ self .assertEqual (line .kwargs , {" color" : " green" , " dashed" : True })
62
69
63
70
def test_coordinates_as_float (self ):
64
- line = Line ((0.5 , 0.5 ), (3.5 , 4.5 ), color = ' green' , dashed = True )
71
+ line = Line ((0.5 , 0.5 ), (3.5 , 4.5 ), color = " green" , dashed = True )
65
72
self .assertEqual (line .start , (0.5 , 0.5 ))
66
73
self .assertEqual (line .end , (3.5 , 4.5 ))
67
74
68
75
def test_negative_coordinates (self ):
69
- line = Line ((- 1 , - 1 ), (- 2 , - 2 ), color = ' green' , dashed = True )
76
+ line = Line ((- 1 , - 1 ), (- 2 , - 2 ), color = " green" , dashed = True )
70
77
self .assertEqual (line .start , (- 1 , - 1 ))
71
78
self .assertEqual (line .end , (- 2 , - 2 ))
72
79
73
80
def test_color_as_none (self ):
74
81
line = Line ((0 , 0 ), (3 , 4 ), color = None , dashed = True )
75
- self .assertEqual (line .kwargs , {' color' : None , ' dashed' : True })
82
+ self .assertEqual (line .kwargs , {" color" : None , " dashed" : True })
76
83
77
84
def test_additional_kwargs (self ):
78
- line = Line ((0 , 0 ), (3 , 4 ), color = 'green' , dashed = True , linewidth = 2 )
79
- self .assertEqual (line .kwargs , {'color' : 'green' , 'dashed' : True , 'linewidth' : 2 })
80
-
81
- if __name__ == '__main__' :
82
- unittest .main ()
85
+ line = Line ((0 , 0 ), (3 , 4 ), color = "green" , dashed = True , linewidth = 2 )
86
+ self .assertEqual (
87
+ line .kwargs , {"color" : "green" , "dashed" : True , "linewidth" : 2 }
88
+ )
89
+
90
+
91
+ class TestArrowObject (unittest .TestCase ):
92
+ def test_arrow_object (self ):
93
+ # Create an ArrowObject instance
94
+ start = (0 , 0 )
95
+ end = (100 , 100 )
96
+ arrow = Arrow (start , end , color = "red" , head_width = 10 , head_length = 20 )
97
+
98
+ # Test that the ArrowObject was created with the correct attributes
99
+ self .assertEqual (arrow .type , "arrow" )
100
+ self .assertEqual (arrow .start , start )
101
+ self .assertEqual (arrow .end , end )
102
+ self .assertEqual (
103
+ arrow .kwargs , {"color" : "red" , "head_width" : 10 , "head_length" : 20 }
104
+ )
105
+
106
+
107
+ class TestTextObject (unittest .TestCase ):
108
+ def test_text_object (self ):
109
+ text = Text (text = "Hello" , position = (100 , 100 ))
110
+ self .assertEqual (text .type , "text" )
111
+ self .assertEqual (text .position , (100 , 100 ))
112
+ self .assertEqual (text .text , "Hello" )
113
+
114
+
115
+ if __name__ == "__main__" :
116
+ unittest .main ()
0 commit comments