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)
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))
def test_create_orc(self): orc = monsters.Orc() expected_stats = {'str': 14, 'con': 8, 'int': 8, 'spd': 8, 'maxhp': 16} actual_stats = { 'str': orc.strength, 'con': orc.constitution, 'int': orc.intelligence, 'spd': orc.speed, 'maxhp': orc.maxhp } self.assertEqual(orc.level, 1) self.assertEqual(actual_stats, expected_stats) self.assertEqual(orc.hp, orc.maxhp)
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)
def test_orc_blood_rage(self): orc = monsters.Orc() orc.blood_rage(self.dummy) self.assertEqual(self.dummy.hp, self.dummy.maxhp - 28) self.assertEqual(orc.hp, orc.maxhp - 4)
def test_orc_slash(self): orc = monsters.Orc() orc.slash(self.dummy) self.assertEqual(self.dummy.hp, self.dummy.maxhp - 26)