-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wizard.py
More file actions
executable file
·303 lines (259 loc) · 9.39 KB
/
test_wizard.py
File metadata and controls
executable file
·303 lines (259 loc) · 9.39 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env python3
## HOMEWORK
# Unit tests:
# test everything your game does
#
# Questions:
# This test's string output, but how do you test arithmetic, etc.
# ex: purse , relax_not_in_forest
#
import unittest
import wiz11
class WizTest(unittest.TestCase):
def test_travel_tower(self):
wiz = wiz11.Wizard(location="village")
self.assertEqual(
wiz11.request(wiz, "tower"),
"You travel to your tower where there is peace and quiet."
)
def test_travel_tower_already_there(self):
wiz = wiz11.Wizard(location="tower")
self.assertEqual(
wiz11.request(wiz, "tower"),
"You are already in the tower."
)
def test_travel_tower_facts(self):
wiz = wiz11.Wizard(location='village')
wiz11.request(wiz, 'tower')
self.assertEqual(
wiz.location,
'tower'
)
def test_travel_village(self):
wiz = wiz11.Wizard(location="tower")
self.assertEqual(
wiz11.request(wiz, "village"),
"You travel to your village where you can work, sell goods and shop."
)
def test_travel_village_already_there(self):
wiz = wiz11.Wizard(location="village")
self.assertEqual(
wiz11.request(wiz, "village"),
"You are already in the village."
)
def test_travel_brc(self):
wiz = wiz11.Wizard(location="tower")
self.assertEqual(
wiz11.request(wiz, "black rock city"),
"You travel to the playa )'(."
)
def test_travel_brc_already_there(self):
wiz = wiz11.Wizard(location="black rock city")
self.assertEqual(
wiz11.request(wiz, "black rock city"),
"You are already in the black rock city."
)
def test_travel_river(self):
wiz = wiz11.Wizard(location="village")
self.assertEqual(
wiz11.request(wiz, "river"),
"You travel to the river where you can have a swim."
)
def test_travel_river_already_there(self):
wiz = wiz11.Wizard(location="river")
self.assertEqual(
wiz11.request(wiz, "river"),
"You are already in the river."
)
def test_travel_river_facts(self):
wiz = wiz11.Wizard(location='village')
wiz11.request(wiz, 'river')
self.assertEqual(
wiz.location,
'river'
)
def test_study_in_tower(self):
wiz = wiz11.Wizard(location="tower")
self.assertEqual(
wiz11.request(wiz, "study"),
"Your skill level is now 1."
)
def test_study_not_tower(self):
for loc in ("village", "black rock city", "forest"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "study"),
"You cannot study in the " + wiz.location + "."
)
def test_study_with_books(self):
wiz = wiz11.Wizard(location="tower", books=1)
self.assertEqual(
wiz11.request(wiz, "study"),
"Your skill level is now 1."
)
def test_study_with_no_books(self):
wiz = wiz11.Wizard(location="tower", books=0)
self.assertEqual(
wiz11.request(wiz, "study"),
"You have no more new books to read."
)
def test_brew_not_tower(self):
for loc in ("village", "black rock city", "forest"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "brew"),
"You cannot brew potions in the " + wiz.location + "."
)
def test_brew_no_mushrooms(self):
wiz = wiz11.Wizard(location="tower", mushrooms=0)
self.assertEqual(
wiz11.request(wiz, "brew"),
"You can't brew potions without mushrooms."
)
def test_brew_tower_mushrooms(self):
wiz = wiz11.Wizard(location="tower", mushrooms=3, potions=1)
self.assertEqual(
wiz11.request(wiz, "brew"),
"You now have 2 potions."
)
self.assertEqual(wiz.mushrooms, 2)
self.assertEqual(wiz.potions, 2)
self.assertEqual(wiz.stress, -1)
def test_forage_in_forest(self):
wiz = wiz11.Wizard(location="forest")
self.assertEqual(
wiz11.request(wiz, "forage"),
"You now have 1 mushrooms."
)
def test_forage_not_forest(self):
for loc in ("village", "black rock city", "tower"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "forage"),
"There are no mushrooms in the " + wiz.location + "."
)
def test_gift_in_brc(self):
wiz = wiz11.Wizard(location="black rock city", potions=6, stress=0)
self.assertEqual(
wiz11.request(wiz, "gift"),
"You now have 5 potions."
)
def test_gift_in_brc_with_stress(self):
wiz = wiz11.Wizard(location="black rock city", potions=6, stress=2)
self.assertEqual(
wiz11.request(wiz, "gift"),
"You now have 5 potions and you have lowered your stress level."
)
def test_gift_not_in_brc(self):
for loc in ("village", "forest", "tower"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "gift"),
"You cannot give gifts in the " + wiz.location + "."
)
def test_gift_no_potions(self):
wiz = wiz11.Wizard(location="black rock city")
self.assertEqual(
wiz11.request(wiz, "gift"),
"You have no potions to gift."
)
def test_purse(self):
wiz = wiz11.Wizard(books=2, gold=2, mushrooms=0, potions=4)
self.assertEqual(
wiz11.request(wiz, "purse"),
''' You have 2 books\n'''
''' You have 2 gold\n'''
''' You have 0 mushrooms\n'''
''' You have 4 potions'''
)
def test_health(self):
wiz = wiz11.Wizard(stress=5, skill=5)
self.assertEqual(
wiz11.request(wiz, "health"),
''' You have a stress level of 5.\n'''
''' You have a skill level of 5.'''
)
def test_relax_in_forest(self):
wiz = wiz11.Wizard(location="forest", stress=1)
self.assertEqual(
wiz11.request(wiz, "relax"),
"You now have 0 stress level."
)
def test_relax_not_in_forest(self):
for loc in ("village", "black rock city", "tower"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "relax"),
"You can't relax in " + wiz.location + "."
)
def test_sell_in_village_no_potions(self):
wiz = wiz11.Wizard(location="village", gold=3)
self.assertEqual(
wiz11.request(wiz, "sell"),
"You have no brewed potions to sell."
)
def test_sell_in_village(self):
wiz = wiz11.Wizard(location="village", gold=3, potions=3)
self.assertEqual(
wiz11.request(wiz, "sell"),
"You now have 4 gold."
)
def test_sell_not_village(self):
for loc in ("tower", "black rock city", "forest"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "sell"),
"You can't sell goods in the " + wiz.location + "."
)
def test_shop_in_village(self):
wiz = wiz11.Wizard(location="village", gold=1)
self.assertEqual(
wiz11.request(wiz, "shop"),
"You now have 2 books and 0 gold."
)
def test_shop_not_village(self):
for loc in ("tower", "black rock city", "forest"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "shop"),
"You can't shop in the " + wiz.location + "."
)
def test_shop_too_stressed(self):
wiz = wiz11.Wizard(location="village", gold=1, stress=11)
self.assertEqual(
wiz11.request(wiz, "shop"),
"You are too stressed out. Go do relaxing things."
)
def test_shop_no_gold(self):
wiz = wiz11.Wizard(location="village", gold=0)
self.assertEqual(
wiz11.request(wiz, "shop"),
"You have 0 gold. You must work to earn gold."
)
def test_work_in_village(self):
wiz = wiz11.Wizard(location="village", gold=2, skill=3)
self.assertEqual(
wiz11.request(wiz, "work"),
"All in a day's work. You now have 3 gold."
)
def test_work_not_village(self):
for loc in ("tower", "black rock city", "forest"):
wiz = wiz11.Wizard(location=loc)
self.assertEqual(
wiz11.request(wiz, "work"),
"There is no work in the " + wiz.location + "."
)
def test_work_no_skills(self):
wiz = wiz11.Wizard(location="village", skill=0)
self.assertEqual(
wiz11.request(wiz, "work"),
"You can't work without any skills."
)
def test_shop_too_stressed(self):
wiz = wiz11.Wizard(location="village", stress=11, skill=2)
self.assertEqual(
wiz11.request(wiz, "work"),
"You are too stressed out. Go do relaxing things."
)
if __name__ =='__main__':
unittest.main()