Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
 def setUp(self):
     self.my_room = Room()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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())
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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))
Esempio n. 14
0
 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))
Esempio n. 15
0
 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))
Esempio n. 16
0
 def setUp(self):
     self.my_room = Room(directions=[Direction.WEST, Direction.NORTH])
Esempio n. 17
0
 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())
Esempio n. 18
0
 def test_delete_enemy(self):
     my_room = Room(enemy=Enemy())
     my_room.delete_enemy()
     self.assertIsNone(my_room.enemy)
Esempio n. 19
0
 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)
Esempio n. 20
0
 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)
Esempio n. 21
0
 def test_meet_enemy_when_no_enemy(self):
     my_hero = Hero(room=Room(enemy=None))
     self.assertIsNone(my_hero.meet_enemy())