コード例 #1
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 = battle.start().splitlines()
        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).splitlines()
        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).splitlines()
        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)
コード例 #2
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))
コード例 #3
0
    def test_defeat(self):
        mage = heroes.Mage()
        dragon = monsters.RedDragon(level=99)
        participants = [mage, dragon]

        battle = Battle(participants)

        with self.assertRaises(Defeat):
            battle.start()
コード例 #4
0
    def test_defeat(self):
        mage = heroes.Mage()
        dragon = monsters.RedDragon(level=99)
        participants = [mage, dragon]

        battle = Battle(participants)

        with self.assertRaises(Defeat):
            battle.start()
コード例 #5
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))
コード例 #6
0
    def test_victory(self):
        rogue = heroes.Rogue(level=99)
        skeleton = monsters.Skeleton()
        participants = [rogue, skeleton]

        battle = Battle(participants)

        battle.start()

        with self.assertRaises(Victory):
            expected_output = 'Skeleton dies!'
            output = battle.execute_command('backstab', skeleton)
            self.assertIn(expected_output, output)
コード例 #7
0
    def test_victory(self):
        rogue = heroes.Rogue(level=99)
        skeleton = monsters.Skeleton()
        participants = [rogue, skeleton]

        battle = Battle(participants)

        battle.start()

        with self.assertRaises(Victory):
            expected_output = 'Skeleton dies!'
            output = battle.execute_command('backstab', skeleton)
            self.assertIn(expected_output, output)
コード例 #8
0
    def test_xp_gain(self):
        cleric = heroes.Cleric()
        troll = monsters.Troll()
        troll.hp = 1
        participants = [cleric, troll]

        battle = Battle(participants)

        before_level = cleric.level

        battle.start()
        with self.assertRaises(Victory):
            battle.execute_command('smite', troll)
        after_level = cleric.level
        self.assertNotEqual(before_level, after_level)
コード例 #9
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)
コード例 #10
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 = battle.start().splitlines()
        # assert False, battle.order
        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).splitlines()
        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).splitlines()
        for line, expected in zip(output, expected_output):
            for item in expected:
                self.assertIn(item, line)
コード例 #11
0
    def test_defeat(self):
        mage = heroes.Mage()
        dragon = monsters.RedDragon(level=99)
        participants = [mage, dragon]

        battle = Battle(participants)

        with self.assertRaises(Defeat):
            output = []
            while not battle.is_hero_turn():
                battle.next_turn()
            else:
                battle.next_turn()
コード例 #12
0
    def test_xp_gain(self):
        cleric = heroes.Cleric()
        troll = monsters.Troll()
        troll.hp = 1
        participants = [cleric, troll]

        battle = Battle(participants)

        before_level = cleric.level

        battle.start()
        with self.assertRaises(Victory):
            battle.execute_command('smite', troll)
        after_level = cleric.level
        self.assertNotEqual(before_level, after_level)