Exemplo n.º 1
0
class TestGameUnit(unittest.TestCase):
    """ This class contains the unit testcase for game 'Attack of the Orcs' """
    def setUp(self):
        """ overrides the setUp fixture of the superclass. """
        self.knight = Knight(name='Foo')
        self.enemy = OrcRider()

    def test_reset_health_meter(self):
        """ unit test fo verify if the health_meter was assigned to default hit points of GameUnit"""
        self.knight.health_meter = 1
        self.knight.reset_health_meter()
        self.assertEqual(self.knight.health_meter, self.knight.max_hp)

    def test_heal_full_healing(self):
        """ unit test fo verify if the health_meter was assigned to default hit points of GameUnit"""
        self.knight.health_meter = 1
        self.knight.heal(full_healing=True)
        self.assertEqual(self.knight.health_meter, self.knight.max_hp)

    def test_heal_partial_healing(self):
        """ unit test fo verify if the health_meter was increased with default  heal_by hit points  """
        self.knight.health_meter = 1
        self.knight.heal(full_healing=False)
        self.assertEqual(self.knight.health_meter, 3)

    def test_show_health_comparison(self):
        self.knight.enemy = None
        with self.assertRaises(AssertionError):
            self.knight.show_health_comparison()

    def test_jump(self):
        self.assertEqual(self.knight.jump, horse_jump)
        self.assertEqual(self.enemy.jump, power_jump)

    def test_attack(self):
        self.knight.enemy = None
        with self.assertRaises(AssertionError):
            self.knight.attack()

    def test_equip_with_accessory_knight(self):
        self.assertEqual(len(self.knight.accessories), 0)
        self.knight.equip_with_accessory('ironjacket')
        self.assertIsInstance(self.knight.accessories[0], IronJacket)

    def test_equip_with_accessory_orc(self):
        self.assertEqual(len(self.enemy.accessories), 0)
        self.enemy.equip_with_accessory('powersuit')
        self.assertIsInstance(self.enemy.accessories[0], OrcPowerSuit)
Exemplo n.º 2
0

from knight import Knight
from gameuniterror import GameUnitError

# See the module docstring for details.
if __name__ == '__main__':
    print("Creating a Knight..")
    knight = Knight("Sir Bar")
    # Assume the Knight has sustained injuries in the combat.
    knight.health_meter = 10
    knight.show_health()
    try:
        # Heal the knight by 100 hit points. This will raise an
        # exception as the Knight can have upto 40 hit points.
        knight.heal(heal_by=100, full_healing=False)

    except GameUnitError as e:
        # Print the information about the error
        print(e)
        print(e.error_message)

    knight.show_health()