def test_entry_allowed(self, mock_verify_entry): mock_verify_entry.return_value = True my_hero = Hero(room=Room('Init Room')) move_room = Room('Move room', condition_to_enter=Obj.RANDOM_KEY) my_hero.entry(move_room) self.assertEqual(my_hero.current_room, move_room) self.assertIsNone(move_room.condition_to_enter)
def test_entry_not_allowed(self, mock_verify_entry, mock_input): mock_verify_entry.return_value = False mock_input.return_value = None init_room = Room('Init Room') my_hero = Hero(room=init_room) move_room = Room(name='Move room', condition_to_enter=Obj.RANDOM_KEY) my_hero.entry(move_room) self.assertEqual(my_hero.current_room, init_room) self.assertIsNotNone(move_room.condition_to_enter)
class TestActionRoom(TestCase): def setUp(self): self.my_room = Room() @patch('builtins.input', lambda: 'N') def test_action_room_N(self): self.assertEqual(self.my_room.action_room(), Direction.NORTH) @patch('builtins.input', lambda: 'North') def test_action_room_North(self): self.assertEqual(self.my_room.action_room(), Direction.NORTH) @patch('builtins.input', lambda: 'S') def test_action_room_S(self): self.assertEqual(self.my_room.action_room(), Direction.SOUTH) @patch('builtins.input', lambda: 'South') def test_action_room_South(self): self.assertEqual(self.my_room.action_room(), Direction.SOUTH) @patch('builtins.input', lambda: 'E') def test_action_room_E(self): self.assertEqual(self.my_room.action_room(), Direction.EAST) @patch('builtins.input', lambda: 'East') def test_action_room_East(self): self.assertEqual(self.my_room.action_room(), Direction.EAST) @patch('builtins.input', lambda: 'W') def test_action_room_W(self): self.assertEqual(self.my_room.action_room(), Direction.WEST) @patch('builtins.input', lambda: 'West') def test_action_room_West(self): self.assertEqual(self.my_room.action_room(), Direction.WEST)
class TestActionRoomTwice(TestCase): def setUp(self): self.my_room = Room(directions=[Direction.WEST, Direction.NORTH]) @patch('builtins.input') def test_ask_direction_unknown_direction(self, mock_input): mock_input.side_effect = ['B', 'N'] self.assertEqual(self.my_room.action_room(), Direction.NORTH) @patch('builtins.input') def test_ask_direction_blocked_direction(self, mock_input): mock_input.side_effect = ['E', 'N'] self.assertEqual(self.my_room.action_room(), Direction.NORTH) @patch('builtins.input') def test_ask_direction_first_direction(self, mock_input): mock_input.side_effect = ['W', 'N'] self.assertEqual(self.my_room.action_room(), Direction.WEST)
def setUp(self): self.my_room = Room()
def test_use_obj_inv_punch(self, mock_input): mock_input.return_value = 1 my_hero = Hero(room=Room(), inventory=[]) self.assertEqual(my_hero.use_obj_inv(is_punch=True), Obj.PUNCH)
def test_use_obj_inv_no_punch(self, mock_input): mock_input.side_effect = [2, 1] my_hero = Hero(room=Room(), inventory=[Obj.GUN]) self.assertEqual(my_hero.use_obj_inv(is_punch=False), Obj.GUN)
def test_defeat_enemy(self, mock_use_obj_inv): mock_use_obj_inv.return_value = Obj.GUN my_hero = Hero(room=Room(enemy=Enemy(kill_by=Obj.GUN)), inventory=[Obj.GUN]) self.assertTrue(my_hero.defeat_enemy())
def test_meet_enemy_when_loose_fight(self, mock_defeat_enemy): mock_defeat_enemy.return_value = False my_hero = Hero(room=Room(enemy=Enemy(kill_by=Obj.GUN))) my_hero.meet_enemy() self.assertFalse(my_hero.is_alive) self.assertIsNotNone(my_hero.current_room.enemy)
def test_delete_condition_to_enter(self): my_room = Room(condition_to_enter=Obj.RANDOM_KEY) my_room.delete_condition_to_enter() self.assertIsNone(my_room.condition_to_enter)
def test_delete_key(self): my_room = Room(obj_in_room=Obj.BATHROOM_KEY) my_room.delete_obj() self.assertIsNone(my_room.obj_in_room)
def test_action_not_dead(self, mock_input): mock_input.return_value = 'N' my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) self.assertEqual(Direction.NORTH, my_hero.action()) self.assertIn(Obj.BATHROOM_KEY, my_hero.inventory)
def test_verify_entry_key_needed_bad_key_selected(self, mock_use_obj_inv): mock_use_obj_inv.return_value = Obj.RANDOM_KEY my_hero = Hero(inventory=[Obj.RANDOM_KEY]) my_room = Room(condition_to_enter=Obj.BATHROOM_KEY) self.assertFalse(my_hero.verify_entry(my_room))
def test_verify_entry_key_needed_no_inventory(self): my_hero = Hero(inventory=[]) my_room = Room(condition_to_enter=Obj.BATHROOM_KEY) self.assertFalse(my_hero.verify_entry(my_room))
def test_verify_entry_no_key_needed(self): my_hero = Hero(inventory=[]) my_room = Room(obj_in_room=None) self.assertTrue(my_hero.verify_entry(my_room))
def setUp(self): self.my_room = Room(directions=[Direction.WEST, Direction.NORTH])
def test_action_dead(self): my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) my_hero.is_alive = False self.assertIsNone(my_hero.action())
def test_delete_enemy(self): my_room = Room(enemy=Enemy()) my_room.delete_enemy() self.assertIsNone(my_room.enemy)
def test_pick_key_with_key(self): my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory) my_hero.pick_obj() self.assertIn(Obj.BATHROOM_KEY, my_hero.inventory) self.assertIsNone(my_hero.current_room.obj_in_room)
def test_pick_key_without_key(self): my_hero = Hero(room=Room(obj_in_room=None)) self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory) my_hero.pick_obj() self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory)
def test_meet_enemy_when_no_enemy(self): my_hero = Hero(room=Room(enemy=None)) self.assertIsNone(my_hero.meet_enemy())