예제 #1
0
class test_attack(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        print(self.shortDescription())

    #Tests if heal function works
    def test_attack_live(self):
        self.monsta.health = 6
        expected = 1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Heal function should not work if total > 10
    def test_attack_die(self):
        self.monsta.health = 4
        expected = -1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Tests if invalid output was printed
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.health(4)

        expected = "K.O.'d"
        actual = self.monsta.attack(6)
        self.assertNotEqual(mock_stdout.getValue(), text)
예제 #2
0
    def test_reset(self):
        """Set status to "Oops", health to -200 and victory_points to 90 on
        a Monster class object, new_monster. Call reset() then check that
        new_monster's status, health and victory_points attributes were
        restored to their initial values."""

        new_monster = Monster("Cookie")
        new_monster.status = "Oops"
        new_monster.health = -200
        new_monster.victory_points = 90
        new_monster.reset()
        self.assertEqual(new_monster.status, "Out of Tokyo")
        self.assertEqual(new_monster.health, 10)
        self.assertEqual(new_monster.victory_points, 0)

        del new_monster
예제 #3
0
    def test_reset(self):
        """Set status to "Oops", health to -200 and victory_points to 90 on
        a Monster class object, new_monster. Call reset() then check that
        new_monster's status, health and victory_points attributes were
        restored to their initial values."""

        new_monster = Monster("Cookie")
        new_monster.status = "Oops"
        new_monster.health = -200
        new_monster.victory_points = 90
        new_monster.reset()
        self.assertEqual(new_monster.status, "Out of Tokyo")
        self.assertEqual(new_monster.health, 10)
        self.assertEqual(new_monster.victory_points, 0)

        del new_monster