Beispiel #1
0
class PlayerDamage(unittest.TestCase):
    def setUp(self):
        self.player = Player('hero')
        self.enemy = Enemy('wolf')

    def test_player_attack(self):
        self.player.attack_enemy(self.enemy)  # call the method after that =>
        # (if all steps of this sequence work as expected means test passed successfully)
        # game -> return enemy.receive_damage(self.attack) ->
        # -> self.lives=1 - self.attack(damage)=1 => self.lives = 0 -> return self.notify_is_dead() ->
        # -> (if not self.is_alive()) -> return self.lives>0 -> False => True ->
        # return f'{self.name} lost'
        self.assertEqual(self.enemy.lives, 0)  # True
        self.assertEqual(self.enemy.is_alive(), False)  # False
        self.assertEqual(self.enemy.notify_if_dead(), 'wolf lost!')  # True
Beispiel #2
0
class TestPlayerDamage():
    def setup(self):
        self.player = Player('hero')
        self.enemy = Enemy('wolf')

    @pytest.mark.enemySuite
    @pytest.mark.playerSuite
    def test_player_attack(self):
        self.player.attack_enemy(self.enemy)  # call the method after that =>
        # (if all steps of this sequence work as expected means test passed successfully)
        # game -> return enemy.receive_damage(self.attack) ->
        # -> self.lives=1 - self.attack(damage)=1 => self.lives = 0 -> return self.notify_is_dead() ->
        # -> (if not self.is_alive()) -> return self.lives>0 -> False => True ->
        # return f'{self.name} lost'
        assert self.enemy.lives == 0  # True
        assert self.enemy.is_alive() is False  # False
        assert self.enemy.notify_if_dead() == 'wolf lost!'  # True
Beispiel #3
0
class PlayerDamage(unittest.TestCase):
    def setUp(self):
        self.player = Player("Mario")
        self.enemy = Enemy("Bowser")

    def test_player_attack(self):
        result = self.player.attack_enemy(self.enemy)
        self.assertEqual(self.enemy.lives, 0)
        self.assertFalse(self.enemy.is_alive())
        self.assertEqual(result, "Bowser lost!")