Example #1
0
 def test_first_attacker(self):
     participants = [
         heroes.Warrior(),
         heroes.Mage(),
         monsters.Orc(),
         monsters.GreenDragon()
     ]
     battle = Battle(participants)
     self.assertTrue(
         isinstance(battle.current_attacker(), monsters.GreenDragon))
Example #2
0
 def test_participants(self):
     participants = [
         heroes.Warrior(),
         heroes.Mage(),
         monsters.Orc(),
         monsters.GreenDragon()
     ]
     battle = Battle(participants)
     for unit in participants:
         self.assertIn(unit, battle.participants)
Example #3
0
 def test_warrior_levelling(self):
     self.hero = heroes.Warrior(level=4)
     self.assertEqual(self.hero.level, 4)
     expected_stats = {'str': 13,
                       'con': 17,
                       'int': 7,
                       'spd': 8,
                       'maxhp': 124,
                       'maxmp': 60}
     actual_stats = {'str': self.hero.strength,
                     'con': self.hero.constitution,
                     'int': self.hero.intelligence,
                     'spd': self.hero.speed,
                     'maxhp': self.hero.maxhp,
                     'maxmp': self.hero.maxmp}
     self.assertEqual(actual_stats, expected_stats)
     self.assertEqual(self.hero.hp, self.hero.maxhp)
     self.assertEqual(self.hero.mp, self.hero.maxmp)
Example #4
0
    def test_one_round_of_combat(self):
        warr = heroes.Warrior()
        mage = heroes.Mage()
        orc = monsters.Orc()
        dragon = monsters.GreenDragon()
        participants = [warr, mage, orc, dragon]
        battle = Battle(participants)

        expected_output = [('GreenDragon hits', 'with poison breath for',
                            'damage!'),
                           ('Orc hits', 'with blood rage for', 'damage!'),
                           ('Orc takes', 'self-inflicted damage!'),
                           ("Mage's turn!", )]
        output = []
        while not battle.is_hero_turn():
            output.extend(battle.next_turn())
        else:
            output.extend(battle.next_turn())

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)

        expected_output = [('Mage hits Orc with fireball for', 'damage!'),
                           ("Warrior's turn!", )]
        output = battle.execute_command('fireball', orc)

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)

        expected_output = [
            ('Warrior hits Orc with shield slam for', 'damage!'),
            ('Orc dies!', ), ('XP rewarded!', ), ('is now level 2!', ),
            ('is now level 2!', ),
            ('GreenDragon hits', 'with tail swipe for', 'damage!'),
            ("Mage's turn!")
        ]
        output = battle.execute_command('shield_slam', orc)

        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)
Example #5
0
 def setUp(self):
     self.hero = heroes.Warrior()
     self.dummy = TargetDummy()