forked from LeanderMcL/Text_Adventure
/
test.py
81 lines (67 loc) · 6.05 KB
/
test.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
import unittest, rooms, doors, engine, output
class TestParsing(unittest.TestCase):
test_room = rooms.Room("test room","This is the short description of the test room.","This is the long description of the test room.",{"north":"test door","west":"second test door"})
second_test_room = rooms.Room("second test room","This is the short description of the second test room.","This is the long description of the second test room.",{"south":"test door","east":"second test door"})
test_door = doors.Door("test door","Describing the test door.",{"south":"test room","north":"second test room"},True,False)
second_test_door = doors.Door("second test door","This is the description of the second test door.",{"east":"test room","west":"second test room"},False,False)
def test_Room_attributes(self):
self.assertEqual("test room",self.test_room.name,"Test room's name should be 'test room'")
self.assertEqual("This is the short description of the test room.",self.test_room.short_desc,"Should spit out the short description of the test room")
self.assertEqual("This is the long description of the test room.",self.test_room.long_desc,"Should spit out the long description of the test room")
self.assertEqual({"north":"test door","west":"second test door"},self.test_room.doors,"Should spit out the doors for the test room.")
def test_Room_show_room_name(self):
self.assertEqual("You are in a test room.",self.test_room.show_room_name(),"Should be 'You are in a test room.'")
def test_Room_show_full_desc(self):
self.assertEqual(self.test_room.show_room_name() + "\n" + self.test_room.long_desc + "\n" + self.test_room.show_doors(),self.test_room.show_full_desc(),"Should show the full description of the room.")
def test_Room_show_doors(self):
self.assertTrue("There is a test door to the north." in self.test_room.show_doors(),"North exit should show up in show_doors.")
def test_find_room(self):
self.assertEqual(rooms.find_room("test room"),self.test_room,"Should be able to find test room.")
def test_show_room(self):
rooms.current_room = self.test_room
self.assertNotEqual(rooms.previous_room,rooms.current_room,"Previous room and current room should be unequal before assignment")
self.assertEqual(rooms.show_room(),self.test_room.show_full_desc(),"Should show full description of room while current room and previous room are unequal.")
rooms.previous_room = rooms.current_room
self.assertTrue(rooms.current_room == rooms.previous_room,"Current room and previous room should be equal after reassignment.")
self.assertEqual(rooms.show_room(),self.test_room.show_room_name(),"Should show only the room name while current room and previous room are equal.")
def test_Door_attributes(self):
self.assertEqual(self.test_door.name,"test door","Should spit out the name of the test door.")
self.assertEqual(self.test_door.desc,"Describing the test door.","Should spit out the description of the test door.")
self.assertEqual(self.test_door.exits,{"south":"test room","north":"second test room"},"Should spit out the exits for the test door.")
self.assertEqual(self.test_door.closed,True,"The test door should be closed.")
self.assertEqual(self.test_door.locked,False,"The test door should not be locked.")
def test_find_door(self):
self.assertEqual(doors.find_door("test door"),self.test_door,"Should be able to find the test door.")
def test_get_action(self):
self.assertEqual(engine.get_action("fish"),(None,None),"Get action should return (None,None) for input 'fish'.")
self.assertEqual(engine.get_action("castle"),(None,None),"Get action should return (None,None) for input 'castle'.")
self.assertEqual(engine.get_action("q"),("quit",None),"Get action should return ('quit',None) for input 'q'.")
self.assertEqual(engine.get_action("look"),("look",None),"Get action should return ('look',None) for input 'look'.")
self.assertEqual(engine.get_action("look n"),("look direction","north"),"Get action should return ('look direction,'north') for input 'look n'.")
self.assertEqual(engine.get_action("look fish"),("look error",None),"Get action should return ('look error',None) for input 'look fish'.")
self.assertEqual(engine.get_action("north"),("move","north"),"Get action should return ('move','north') for input 'north'.")
def test_do_action(self):
rooms.current_room = self.test_room
self.assertEqual(engine.do_action("look direction","north"),self.test_door.desc,"Looking at a closed door should generate the door description.")
self.assertEqual(engine.do_action("look direction","west"),self.second_test_room.short_desc,"Looking through an open door should generate the short description of the room on the other side.")
print engine.do_action("look direction","up")
print output.look_direction_error
self.assertEqual(engine.do_action("look directon","up"),output.look_direction_error,"Looking in a direction where there is no exit should generate an error message.")
"""
def test_get_argument(self):
self.assertEqual('north', get_argument("look north"), "look north Should be north")
self.assertEqual('fish', get_argument("get fish"), "get fish Should be fish")
self.assertEqual(False, get_argument("Bajorans"), "Should be False")
def test_check_look_direction(self):
self.assertEqual('north', check_look_direction("look north"), "look north Should be north")
self.assertEqual('fish', check_look_direction("l fish"), "l fish Should be fish")
self.assertEqual(False, check_look_direction("gobbledegook"), "gobbledegook Should be False")
def test_string_matching(self):
self.assertEqual(True, match_any(quit_strings,"exit please"), "exit please Should be True")
self.assertEqual(True, match_any(look_strings,"look fish"), "look fish Should be True")
self.assertEqual(True, match_any(move_strings,"dance north"), "dance north Should be True")
self.assertEqual(False, match_any(quit_strings,"fish"), "fish Should be False")
self.assertEqual(False, match_any(look_strings,"this string is gobbledegook"), " this string is gobbledegook Should be False")
"""
if __name__ == '__main__':
unittest.main()