-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_module.py
152 lines (133 loc) · 5.33 KB
/
test_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import unittest
import shape_calculator
class UnitTests(unittest.TestCase):
def setUp(self):
self.rect = shape_calculator.Rectangle(3, 6)
self.sq = shape_calculator.Square(5)
def test_subclass(self):
actual = issubclass(shape_calculator.Square,
shape_calculator.Rectangle)
expected = True
self.assertEqual(
actual, expected,
'Expected Square class to be a subclass of the Rectangle class.')
def test_distinct_classes(self):
actual = shape_calculator.Square is not shape_calculator.Rectangle
expected = True
self.assertEqual(
actual, expected,
'Expected Square class to be a distinct class from the Rectangle class.'
)
def test_square_is_square_and_rectangle(self):
actual = isinstance(self.sq, shape_calculator.Square) and isinstance(
self.sq, shape_calculator.Square)
expected = True
self.assertEqual(
actual, expected,
'Expected square object to be an instance of the Square class and the Rectangle class.'
)
def test_rectangle_string(self):
actual = str(self.rect)
expected = "Rectangle(width=3, height=6)"
self.assertEqual(
actual, expected,
'Expected string representation of rectangle to be "Rectangle(width=3, height=6)"'
)
def test_square_string(self):
actual = str(self.sq)
expected = "Square(side=5)"
self.assertEqual(
actual, expected,
'Expected string representation of square to be "Square(side=5)"')
actual = self.rect.get_area()
expected = 18
self.assertEqual(actual, expected,
'Expected area of rectangle to be 18')
actual = self.sq.get_area()
expected = 25
self.assertEqual(actual, expected,
'Expected area of rectangle to be 25')
def test_perimeter(self):
actual = self.rect.get_perimeter()
expected = 18
self.assertEqual(actual, expected,
'Expected perimeter of rectangle to be 18')
actual = self.sq.get_perimeter()
expected = 20
self.assertEqual(actual, expected,
'Expected perimeter of rectangle to be 20')
def test_diagonal(self):
actual = self.rect.get_diagonal()
expected = 6.708203932499369
self.assertEqual(
actual, expected,
'Expected diagonal of rectangle to be 6.708203932499369')
actual = self.sq.get_diagonal()
expected = 7.0710678118654755
self.assertEqual(
actual, expected,
'Expected diagonal of rectangle to be 7.0710678118654755')
def test_set_atributes(self):
self.rect.set_width(7)
self.rect.set_height(8)
self.sq.set_side(2)
actual = str(self.rect)
expected = "Rectangle(width=7, height=8)"
self.assertEqual(
actual, expected,
'Expected string representation of rectangle after setting new values to be "Rectangle(width=7, height=8)"'
)
actual = str(self.sq)
expected = "Square(side=2)"
self.assertEqual(
actual, expected,
'Expected string representation of square after setting new values to be "Square(side=2)"'
)
self.sq.set_width(4)
actual = str(self.sq)
expected = "Square(side=4)"
self.assertEqual(
actual, expected,
'Expected string representation of square after setting width to be "Square(side=4)"'
)
def test_rectangle_picture(self):
self.rect.set_width(7)
self.rect.set_height(3)
actual = self.rect.get_picture()
expected = "*******\n*******\n*******\n"
self.assertEqual(actual, expected,
'Expected rectangle picture to be different.')
def test_squaree_picture(self):
self.sq.set_side(2)
actual = self.sq.get_picture()
expected = "**\n**\n"
self.assertEqual(actual, expected,
'Expected square picture to be different.')
def test_big_picture(self):
self.rect.set_width(51)
self.rect.set_height(3)
actual = self.rect.get_picture()
expected = "Too big for picture."
self.assertEqual(actual, expected,
'Expected message: "Too big for picture."')
def test_get_amount_inside(self):
self.rect.set_height(10)
self.rect.set_width(15)
actual = self.rect.get_amount_inside(self.sq)
expected = 6
self.assertEqual(actual, expected,
'Expected `get_amount_inside` to return 6.')
def test_get_amount_inside_two_rectangles(self):
rect2 = shape_calculator.Rectangle(4, 8)
actual = rect2.get_amount_inside(self.rect)
expected = 1
self.assertEqual(actual, expected,
'Expected `get_amount_inside` to return 1.')
def test_get_amount_inside_none(self):
rect2 = shape_calculator.Rectangle(2, 3)
actual = rect2.get_amount_inside(self.rect)
expected = 0
self.assertEqual(actual, expected,
'Expected `get_amount_inside` to return 0.')
if __name__ == "__main__":
unittest.main()