-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_model.py
233 lines (192 loc) · 7.21 KB
/
tests_model.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env python
"""tests_model.py: Tests for the model of the educational game Trusty Brusher."""
import sys
import time
from tooth import Tooth
from germ import Germ
from food import Food
from person import Person
from calendar_clock import Calendar_Clock
def test_tooth_class():
"""
First, test Tooth class.
"""
try:
tooth_1 = Tooth(1, False, 0)
assert tooth_1.get_location() == 1
assert tooth_1.get_cavity_status() == False
assert tooth_1.get_germ_count() == 0
tooth_1.set_location(21)
tooth_1.set_cavity_status(True)
tooth_1.set_germ_count(10)
assert tooth_1.get_location() == 21
assert tooth_1.get_cavity_status() == True
assert tooth_1.get_germ_count() == 10
print("All Tooth class tests pass!")
except:
message_1 = sys.exc_info()[0]
message_2 = sys.exc_info()[2]
print("Caught an error: {}\n {}".format(message_1, message_2))
def test_germ_class():
"""
Test Germ class.
"""
try:
germ_1 = Germ(52, 10)
assert germ_1.get_location() == 52
assert germ_1.get_health() == 10
germ_1.set_location(103)
germ_1.set_health(2)
assert germ_1.get_location() == 103
assert germ_1.get_health() == 2
germ_1.increment_health()
assert germ_1.get_health() == 3
germ_1.decrement_health()
germ_1.decrement_health()
germ_1.decrement_health()
assert germ_1.get_health() == 0
germ_1.decrement_health()
assert germ_1.get_health() == 0
print("All Germ class tests pass!")
except:
message_1 = sys.exc_info()[0]
message_2 = sys.exc_info()[2]
print("Caught an error: {}\n {}".format(message_1, message_2))
def test_food_class():
"""
Test Food class.
"""
try:
ice_cream_cone = Food("ice cream cone", 10, 1)
assert ice_cream_cone.get_food_type() == "ice cream cone"
assert ice_cream_cone.get_decay_value() == 10
assert ice_cream_cone.get_cleaning_value() == 1
ice_cream_cone.set_food_type("strawberry ice cream cone")
assert ice_cream_cone.get_food_type() == "strawberry ice cream cone"
carrot = Food("carrot", 2, 10)
carrot.set_decay_value(1)
carrot.set_cleaning_value(15)
assert carrot.get_decay_value() == 1
assert carrot.get_cleaning_value() == 15
print("All Food class tests pass!")
except:
message_1 = sys.exc_info()[0]
message_2 = sys.exc_info()[2]
print("Caught an error: {}\n {}".format(message_1, message_2))
def test_person_class():
"""
Test Person class.
"""
try:
Bobby = Person("Bobby", "Male")
assert Bobby.get_name() == "Bobby"
assert Bobby.get_gender() == "Male"
Bobby.set_name("Robert")
assert Bobby.get_name() == "Robert"
Abbie = Person("Abbie", "Female")
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == False
Abbie.go_to_sleep()
assert Abbie.get_is_awake() == False
assert Abbie.get_is_sleeping() == True
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == False
Abbie.eat()
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == True
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == False
Abbie.hurt()
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == True
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == False
Abbie.brush_teeth()
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == True
assert Abbie.get_is_flossing() == False
Abbie.floss_teeth()
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == True
Abbie.be_alert()
assert Abbie.get_is_awake() == True
assert Abbie.get_is_sleeping() == False
assert Abbie.get_is_eating() == False
assert Abbie.get_is_hurting() == False
assert Abbie.get_is_brushing() == False
assert Abbie.get_is_flossing() == False
Abbie.toggle_awake()
assert Abbie.get_is_awake() == False
Abbie.toggle_sleeping()
assert Abbie.get_is_sleeping() == True
Abbie.toggle_eating()
assert Abbie.get_is_eating() == True
Abbie.toggle_hurting()
assert Abbie.get_is_hurting() == True
Abbie.toggle_brushing()
assert Abbie.get_is_brushing() == True
Abbie.toggle_flossing()
assert Abbie.get_is_flossing() == True
print("All Person class tests pass!")
except:
message_1 = sys.exc_info()[0]
message_2 = sys.exc_info()[2]
print("Caught an error: {}\n {}".format(message_1, message_2))
def test_calendar_clock_class():
"""
Test Calendar_Clock class.
"""
try:
timekeeper = Calendar_Clock()
assert timekeeper.get_time_stamp() == "SUNDAY 07:00"
assert timekeeper.get_day() == "SUNDAY"
assert timekeeper.get_hour() == 7
assert timekeeper.get_minute() == 0
custom_clock = Calendar_Clock("Thursday", 0, 32)
assert custom_clock.get_time_stamp() == "THURSDAY 00:32"
assert custom_clock.get_day() == "THURSDAY"
assert custom_clock.get_hour() == 0
assert custom_clock.get_minute() == 32
custom_clock.set_day("Saturday")
custom_clock.set_hour(23)
custom_clock.set_minute(55)
assert custom_clock.get_time_stamp() == "SATURDAY 23:55"
assert custom_clock.get_day() == "SATURDAY"
assert custom_clock.get_hour() == 23
assert custom_clock.get_minute() == 55
custom_clock.start()
for counter in range(10):
print(custom_clock.get_time_stamp())
time.sleep(0.1)
custom_clock.stop()
custom_clock.join()
print("All Calendar_Clock class tests pass!")
except:
message_1 = sys.exc_info()[0]
message_2 = sys.exc_info()[2]
print("Caught an error: {}\n {}".format(message_1, message_2))
def main():
test_tooth_class()
test_germ_class()
test_food_class()
test_person_class()
test_calendar_clock_class()
if __name__ =='__main__':
main()