-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ifs_world.py
261 lines (176 loc) · 11.6 KB
/
test_ifs_world.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
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
import pytest
import world
import json
def test_loads_file():
# tests if the map is loaded into a variable.
assert world.load_file() == {"PLAYER": "0", "OBJECTS": ["Vase", "Knife", "Ball"], "Vase": ["1", "There is a blue vase in the room."], "Knife": ["7", "You can see a knife in front of you."], "Ball": ["5", "There is a red tennis ball in front of you."], "0": ["You are standing at the end of a corridor. There is a door in front of you.", ["S", "1"]], "1": ["You are standing in what seems to be a living room.", ["E", "2"], ["N", "0"]], "2": ["You are standing in what seems to be a hall way connecting many room.", ["W", "1"], ["N", "3"], ["E", "5"], ["S", "6"]], "3": ["Your are standing in what seems to be a bedroom. It has got a balcony attached.", ["E", "4"], ["S", "2"]], "4": ["You are standing in the balcony of Room number 3.", ["W", "3"]], "5": ["You are standing in the balcony attached to the hallway.", ["W", "2"]], "6": ["You are standing in a connecting hallway. Three doors await you.", ["N", "2"], ["S", "9"], ["E", "7"], ["W", "8"]], "7": ["You are standing in a kitchen. Utensils everywhere.", ["W", "6"]], "8": ["You are standing in another bedroom. You can see a door that seems to lead to a balcony number 2.", ["E", "6"], ["S", "10"]], "9": ["You are standing in another bedroom. You can see a door that seems to lead to a balcony number 3.", ["N", "6"], ["S", "11"]], "10": ["You are standing in the balcony of room number 8.", ["N", "8"]], "11": ["You are standing in the balcony of room number 9.", ["N", "9"]]}
def test_start_position():
# tesrs if the start position returns the description of the zeroth room
assert world.start_position() == "You are standing at the end of a corridor. There is a door in front of you."
# Zeroth Room
def test_wrong_exit_0_1():
# to test the output in case of no exit
assert world.if_exit("0", "N") == ("No exit that way", "0", '\n')
def test_wrong_exit_0_2():
# to test the output in case of no exit
assert world.if_exit("0", "E") == ("No exit that way", "0", '\n')
def test_wrong_exit_0_3():
# to test the output in case of no exit
assert world.if_exit("0", "W") == ("No exit that way", "0", '\n')
def test_correct_exit_0_4():
# to test in case of correct exit
assert world.if_exit("0", "S") == ("You are standing in what seems to be a living room.", '1', "There is a blue vase in the room.\n")
# First Room
def test_wrong_exit_1_1():
# to test the output in case of no exit
assert world.if_exit("1", "W") == ("No exit that way", "1", '\n')
def test_wrong_exit_1_2():
# to test the output in case of no exit
assert world.if_exit("1", "S") == ("No exit that way", "1", '\n')
def test_correct_exit_1_3():
# to test in case of correct exit
assert world.if_exit("1", "E") == ('You are standing in what seems to be a hall way connecting many room.', '2', '\n')
def test_correct_exit_1_4():
# to test in case of correct exit
assert world.if_exit("1", "N") == ("You are standing at the end of a corridor. There is a door in front of you.", '0', '\n')
# Room number 2
def test_correct_exit_2_1():
# to test in case of correct exit
assert world.if_exit("2", "S") == ('You are standing in a connecting hallway. Three doors await you.', '6', '\n')
def test_correct_exit_2_2():
# to test in case of correct exit
assert world.if_exit("2", "N") == ('Your are standing in what seems to be a bedroom. It has got a balcony attached.', '3', '\n')
def test_correct_exit_2_3():
# to test in case of correct exit
assert world.if_exit("2", "E") == ('You are standing in the balcony attached to the hallway.', '5', "There is a red tennis ball in front of you.\n")
def test_correct_exit_2_4():
# to test in case of correct exit
assert world.if_exit("2", "W") == ('You are standing in what seems to be a living room.', '1', "There is a blue vase in the room.\n")
# Third Room
def test_wrong_exit_3_1():
# to test the output in case of no exit
assert world.if_exit("3", "N") == ("No exit that way", "3", '\n')
def test_wrong_exit_3_2():
# to test the output in case of no exit
assert world.if_exit("3", "W") == ("No exit that way", "3", '\n')
def test_correct_exit_3_3():
# to test in case of correct exit
assert world.if_exit("3", "S") == ('You are standing in what seems to be a hall way connecting many room.', '2', '\n')
def test_correct_exit_3_4():
# to test in case of correct exit
assert world.if_exit("3", "E") == ('You are standing in the balcony of Room number 3.', '4', '\n')
# Forth Room
def test_wrong_exit_4_1():
# to test the output in case of no exit
assert world.if_exit("4", "N") == ("No exit that way", "4", '\n')
def test_wrong_exit_4_2():
# to test the output in case of no exit
assert world.if_exit("4", "E") == ("No exit that way", "4", '\n')
def test_wrong_exit_4_3():
# to test the output in case of no exit
assert world.if_exit("4", "S") == ("No exit that way", "4", '\n')
def test_correct_exit_4_4():
# to test in case of correct exit
assert world.if_exit("4", "W") == ('Your are standing in what seems to be a bedroom. It has got a balcony attached.', '3', '\n')
# Fifth Room
def test_wrong_exit_5_1():
# to test the output in case of no exit
assert world.if_exit("5", "N") == ("No exit that way", "5", '\n')
def test_wrong_exit_5_2():
# to test the output in case of no exit
assert world.if_exit("5", "E") == ("No exit that way", "5", '\n')
def test_wrong_exit_5_3():
# to test the output in case of no exit
assert world.if_exit("5", "S") == ("No exit that way", "5", '\n')
def test_correct_exit_5_4():
# to test in case of correct exit
assert world.if_exit("5", "W") == ('You are standing in what seems to be a hall way connecting many room.', '2', '\n')
# Sixth Room
def test_correct_exit_6_1():
# to test in case of correct exit
assert world.if_exit("6", "S") == ('You are standing in another bedroom. You can see a door that seems to lead to a balcony number 3.', '9', '\n')
def test_correct_exit_6_2():
# to test in case of correct exit
assert world.if_exit("6", "N") == ('You are standing in what seems to be a hall way connecting many room.', '2', '\n')
def test_correct_exit_6_3():
# to test in case of correct exit
assert world.if_exit("6", "E") == ('You are standing in a kitchen. Utensils everywhere.', '7', "You can see a knife in front of you.\n")
def test_correct_exit_6_4():
# to test in case of correct exit
assert world.if_exit("6", "W") == ('You are standing in another bedroom. You can see a door that seems to lead to a balcony number 2.', '8', '\n')
# Seventh Room
def test_wrong_exit_7_1():
# to test the output in case of no exit
assert world.if_exit("7", "N") == ("No exit that way", "7", '\n')
def test_wrong_exit_7_2():
# to test the output in case of no exit
assert world.if_exit("7", "E") == ("No exit that way", "7", '\n')
def test_wrong_exit_7_3():
# to test the output in case of no exit
assert world.if_exit("7", "S") == ("No exit that way", "7", '\n')
def test_correct_exit_7_4():
# to test in case of correct exit
assert world.if_exit("7", "W") == ('You are standing in a connecting hallway. Three doors await you.', '6', '\n')
# Eigth Room
def test_wrong_exit_8_1():
# to test the output in case of no exit
assert world.if_exit("8", "N") == ("No exit that way", "8", '\n')
def test_wrong_exit_8_2():
# to test the output in case of no exit
assert world.if_exit("8", "W") == ("No exit that way", "8", '\n')
def test_correct_exit_8_3():
# to test in case of correct exit
assert world.if_exit("8", "S") == ('You are standing in the balcony of room number 8.', '10', '\n')
def test_correct_exit_8_4():
# to test in case of correct exit
assert world.if_exit("8", "E") == ('You are standing in a connecting hallway. Three doors await you.', '6', '\n')
# Ninth Room
def test_wrong_exit_9_1():
# to test the output in case of no exit
assert world.if_exit("9", "E") == ("No exit that way", "9", '\n')
def test_wrong_exit_9_2():
# to test the output in case of no exit
assert world.if_exit("9", "W") == ("No exit that way", "9", '\n')
def test_correct_exit_9_3():
# to test in case of correct exit
assert world.if_exit("9", "N") == ('You are standing in a connecting hallway. Three doors await you.', '6', '\n')
def test_correct_exit_9_4():
# to test in case of correct exit
assert world.if_exit("9", "S") == ('You are standing in the balcony of room number 9.', '11', '\n')
# Tenth Room
def test_wrong_exit_10_1():
# to test the output in case of no exit
assert world.if_exit("10", "W") == ("No exit that way", "10", '\n')
def test_wrong_exit_10_2():
# to test the output in case of no exit
assert world.if_exit("10", "E") == ("No exit that way", "10", '\n')
def test_wrong_exit_10_3():
# to test the output in case of no exit
assert world.if_exit("10", "S") == ("No exit that way", "10", '\n')
def test_correct_exit_10_4():
# to test in case of correct exit
assert world.if_exit("10", "N") == ('You are standing in another bedroom. You can see a door that seems to lead to a balcony number 2.', '8', '\n')
# Eleventh Room
def test_wrong_exit_11_1():
# to test the output in case of no exit
assert world.if_exit("11", "W") == ("No exit that way", "11", '\n')
def test_wrong_exit_11_2():
# to test the output in case of no exit
assert world.if_exit("11", "E") == ("No exit that way", "11", '\n')
def test_wrong_exit_11_3():
# to test the output in case of no exit
assert world.if_exit("11", "S") == ("No exit that way", "11", '\n')
def test_correct_exit_11_4():
# to test in case of correct exit
assert world.if_exit("11", "N") == ('You are standing in another bedroom. You can see a door that seems to lead to a balcony number 3.', '9', '\n')
def test_save_file():
file_name ={"PLAYER": "3", "OBJECTS": ["Vase", "Knife", "Ball"], "Vase": ["1", "There is a blue vase in the room."], "Knife": ["7", "You can see a knife in front of you."], "Ball": ["5", "There is a red tennis ball in front of you."], "0": ["You are standing at the end of a corridor. There is a door in front of you.", ["S", "1"]], "1": ["You are standing in what seems to be a living room.", ["E", "2"], ["N", "0"]], "2": ["You are standing in what seems to be a hall way connecting many room.", ["W", "1"], ["N", "3"], ["E", "5"], ["S", "6"]], "3": ["Your are standing in what seems to be a bedroom. It has got a balcony attached.", ["E", "4"], ["S", "2"]], "4": ["You are standing in the balcony of Room number 3.", ["W", "3"]], "5": ["You are standing in the balcony attached to the hallway.", ["W", "2"]], "6": ["You are standing in a connecting hallway. Three doors await you.", ["N", "2"], ["S", "9"], ["E", "7"], ["W", "8"]], "7": ["You are standing in a kitchen. Utensils everywhere.", ["W", "6"]], "8": ["You are standing in another bedroom. You can see a door that seems to lead to a balcony number 2.", ["E", "6"], ["S", "10"]], "9": ["You are standing in another bedroom. You can see a door that seems to lead to a balcony number 3.", ["N", "6"], ["S", "11"]], "10": ["You are standing in the balcony of room number 8.", ["N", "8"]], "11": ["You are standing in the balcony of room number 9.", ["N", "9"]]}
world.save_file(file_name)
wrapper = open("./maps.json", "r+")
data = wrapper.readline()
load = json.loads(data)
assert load["PLAYER"] == "3"
def test_object_description():
assert world.object_description('1') == 'There is a blue vase in the room.\n'
def test_get_exits():
assert world.get_exits("2") == 'The exits are W N E S'