def test_move_command_valid_move(self): user_input = "north" player = copy.copy(Test_Objects.TEST_PLAYER) room = copy.copy(Test_Objects.TEST_ROOM) room_two = copy.copy(Test_Objects.TEST_ROOM_2) self.assertEqual(player.location.desc, room.desc) Commands.parse_move_command(user_input, player) self.assertEqual(player.location.desc, room_two.desc)
def parse_single_target_command(user_input, player): command = user_input[0] if command in Constants.EXAMINE: return Commands.parse_examine_command(user_input, player) if command in Constants.TAKE: return Commands.parse_take_command(user_input, player) if command in Constants.TALK: return Commands.parse_talk_command(user_input, player) return Constants.INVALID_COMMAND_GIVEN_STRING
def test_move_command_invalid_move(self): user_input = "west" player = copy.copy(Test_Objects.TEST_PLAYER) room = copy.copy(Test_Objects.TEST_ROOM) self.assertEqual(player.location.desc, room.desc) actual = Commands.parse_move_command(user_input, player) self.assertEqual(Constants.EXIT_NOT_FOUND_STRING, actual)
def parse_untargetable_command(user_input, player): command = user_input[0] if command in Constants.DIRECTIONS[0]: return Commands.parse_move_command(user_input, player) if command in Constants.HELP: return Commands.parse_help_command() if command in Constants.LOOK: return Commands.parse_look_command(player) if command in Constants.QUIT: return Commands.parse_quit_command() if command in Constants.INVENTORY: return Commands.parse_inventory_command(player) # If the command is in the targeted commands like 'examine' or 'give', tell the player this. if is_command_valid( user_input, Constants.SINGLE_TARGET_COMMANDS + Constants.DOUBLE_TARGET_COMMANDS): return Constants.IMPROPERLY_TARGETED_COMMAND return Constants.INVALID_COMMAND_GIVEN_STRING
def test_take_command_item_not_present(self): user_input = ["take", "test not present"] player = copy.copy(Test_Objects.TEST_PLAYER) room = Room.Room("Test Room", "This is a test room for testing.", {}, [Test_Objects.TEST_ITEM_ON_GROUND], []) item = copy.copy(Test_Objects.TEST_ITEM_NOT_PRESENT) self.assertTrue(item not in room.items) self.assertTrue(item not in player.inventory) actual = Commands.parse_take_command(user_input, player) self.assertTrue(item not in room.items) self.assertTrue(item not in player.inventory) self.assertEqual(Constants.ITEM_NOT_VISIBLE_STRING, actual)
def test_take_command_item_with_keyword(self): user_input = ["take", "keyword"] item = Item.Item("test 2", ["keyword"], "Short desc 2", "Long desc 2", True, True) room = Room.Room("Test Room", "This is a test room for testing.", {}, [item], []) player = Player.Player(room, [Test_Objects.TEST_ITEM_IN_INVENTORY]) self.assertTrue(item in room.items) self.assertTrue(item not in player.inventory) actual = Commands.parse_take_command(user_input, player) self.assertTrue(item not in room.items) self.assertTrue(item in player.inventory) self.assertEqual("You take the test 2.", actual)
def parse_double_target_command(user_input, player): command = user_input[0] if command in Constants.GIVE: return Commands.parse_give_command(user_input, player) return Constants.INVALID_COMMAND_GIVEN_STRING
def test_examine_command_item_not_found(self): user_input = ["examine", "test not present"] player = copy.copy(Test_Objects.TEST_PLAYER) expected = Constants.ITEM_NOT_VISIBLE_STRING + "test not present." actual = Commands.parse_examine_command(user_input, player) self.assertEqual(expected, actual)
def test_examine_command_with_keyword(self): user_input = ["examine", "keyword"] player = copy.copy(Test_Objects.TEST_PLAYER) actual = Commands.parse_examine_command(user_input, player) self.assertEqual(Test_Objects.TEST_ITEM_ON_GROUND.long_desc, actual)
def test_examine_command_item_in_inventory(self): user_input = ["examine", "test"] player = copy.copy(Test_Objects.TEST_PLAYER) actual = Commands.parse_examine_command(user_input, player) self.assertEqual(Test_Objects.TEST_ITEM_IN_INVENTORY.long_desc, actual)
def test_help_command(self): actual = Commands.parse_help_command() self.assertEqual(Constants.PLAYER_HELP, actual)
def test_look_command(self): player = copy.copy(Test_Objects.TEST_PLAYER) actual = Commands.parse_look_command(player) self.assertEqual(player.location.desc, actual)
def test_talk_command_person_invisible(self): user_input = ["talk", "testman"] player = copy.copy(Test_Objects.TEST_PLAYER_IN_INVISIBLE_PERSON_ROOM) actual = Commands.parse_talk_command(user_input, player) self.assertEqual(Constants.BASE_DIALOGUE, actual)
def test_give_command_item_not_in_inventory(self): user_input = ["give", "testman", "test not present"] player = copy.copy(Test_Objects.TEST_PLAYER_IN_INVISIBLE_PERSON_ROOM) actual = Commands.parse_give_command(user_input, player) expected = Constants.ITEM_NOT_IN_INVENTORY_STRING + "test not present." self.assertEqual(expected, actual)
def test_give_command_person_not_present(self): user_input = ["give", "testman", "test"] player = copy.copy(Test_Objects.TEST_PLAYER) actual = Commands.parse_give_command(user_input, player) expected = Constants.PERSON_NOT_VISIBLE_STRING + "testman." self.assertEqual(expected, actual)
def test_give_command_with_keyword(self): user_input = ["give", "testman", "keyword"] player = copy.copy(Test_Objects.TEST_PLAYER_IN_PERSON_ROOM) actual = Commands.parse_give_command(user_input, player) self.assertEqual(Constants.INCORRECT_GIFT, actual)
def test_talk_command_person_not_present(self): user_input = ["talk", "testman"] player = copy.copy(Test_Objects.TEST_PLAYER) actual = Commands.parse_talk_command(user_input, player) self.assertEqual(Constants.PERSON_NOT_VISIBLE_STRING, actual)