Beispiel #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)
    def setUp(self):
        """Overrides the setUp fixture of the superclass.

        This method is called just before the calling each unit test. Here, it
        creates instances of Knight and OrcRider for use by various unit tests.

        .. seealso:: TestCase.tearDown()
        """
        self.knight = Knight()
        self.enemy = OrcRider()
Beispiel #3
0
    def test(self):
        self.player = Knight()
        self.player.info()
        self.player.show_health(bold=False)

        knight = self.player
        knight.jump()
        knight.jump = can_not_jump
        knight.jump()

        knight.equip_with_accessory('ironjacket')
        knight.equip_with_accessory('superlocket')
        knight.show_details()

        print_dotted_line()

        orc = OrcRider('Orc战士')
        orc.info()
        orc.equip_with_accessory('powersuit')
        orc.equip_with_accessory('magiclocket')
        orc.show_details()
Beispiel #4
0
 def _occupy_huts(self, n=5):
     occupants = ['friend', 'enemy', None]
     for i in range(n):
         computer_choose = random.choice(occupants)
         if computer_choose == 'friend':
             name = 'friend' + str(i + 1)
             self.huts.append(Hut(i + 1, Knight(name)))
         elif computer_choose == 'enemy':
             name = 'enemy' + str(i + 1)
             self.huts.append(Hut(i + 1, OrcRider(name)))
         else:
             self.huts.append(Hut(i + 1, computer_choose))
Beispiel #5
0
 def _occupy_huts(self):
     """Randomly occupy the huts with one of: friend, enemy or 'None'"""
     for i in range(5):
         choice_lst = ['enemy', 'friend', None]
         computer_choice = random.choice(choice_lst)
         if computer_choice == 'enemy':
             name = 'enemy-' + str(i + 1)
             self.huts.append(Hut(i + 1, OrcRider(name)))
         elif computer_choice == 'friend':
             name = 'knight-' + str(i + 1)
             self.huts.append(Hut(i + 1, Knight(name)))
         else:
             self.huts.append(Hut(i + 1, computer_choice))
Beispiel #6
0
 def occupy_huts(self):
     occupants = ['enemy', 'friend', None]  # 木屋占有人的类型
     # Randomly append 'enemy' or 'friend' or None to the huts list
     for i in range(5):
         computer_choice  = random.choice(occupants)
         if computer_choice == 'enemy':
             name  = 'enemy-' + str(i+1)
             self.huts.append(Hut(i+1, OrcRider(name)))
         elif computer_choice == 'friend':
             name = 'friend-' + str(i+1)
             self.huts.append(Hut(i+1, Knight(name)))
         else:
             self.huts.append(Hut(i+1, computer_choice))
Beispiel #7
0
 def _occupy_huts(self):
     """Metoda koja koristi random funkciju za nastambu kucica s prijatelj, neprijatelj ili 'None'"""
     for i in range(5):
         choice_lst = ['neprijatelj', 'prijatelj', None]
         computer_choice = random.choice(choice_lst)
         if computer_choice == 'neprijatelj':
             name = 'neprijatelj-' + str(i + 1)
             self.huts.append(Hut(i + 1, OrcRider(name)))
         elif computer_choice == 'prijatelj':
             name = 'vitez-' + str(i + 1)
             self.huts.append(Hut(i + 1, Knight(name)))
         else:
             self.huts.append(Hut(i + 1, computer_choice))
Beispiel #8
0
    def _occupy_huts(self):
        print_bold('发现{}座木屋!'.format(self.hut_number))
        """Randomly occupy the hut with one of : friend, enemy or None"""
        for i in range(self.hut_number):
            choice_list = ['敌人', '朋友', None]
            computer_choice = random.choice(choice_list)

            # 根据计算机随机选择木屋里是敌人、队友或是空的
            if computer_choice == '敌人':
                name = '敌人-' + str(i + 1)
                self.huts.append(Hut(i + 1, OrcRider(name)))
            elif computer_choice == '朋友':
                name = '骑士-' + str(i + 1)
                self.huts.append(Hut(i + 1, Knight(name)))
            else:
                self.huts.append(Hut(i + 1, computer_choice))
    def _occupy_huts(self):
        """Randomly occupy the huts with one of the options (friend, enemy or 'None')

        .. todo::
            Here we assume there are exactly 5 huts. As an exercise, make it a user
            input. Note that after such change, the unit test is expected to fail!
        """
        choice_lst = ['friend', 'enemy', None]
        for i in range(5):
            computer_choice = random.choice(choice_lst)
            if computer_choice == 'enemy':
                name = 'enemy-' + str(i + 1)
                self.huts.append(Hut(i + 1, OrcRider(name)))
            elif computer_choice == 'friend':
                name = 'knight-' + str(i + 1)
                self.huts.append(Hut(i + 1, Knight(name)))
            else:
                self.huts.append(Hut(i + 1, computer_choice))
 def setUp(self):
     """Overrides the setUp fixture of the superclass"""
     self.knight = Knight()
     self.enemy = OrcRider()
Beispiel #11
0
 def setUp(self):
     """priprema za testove"""
     self.knight = Knight()
     self.enemy = OrcRider()
Beispiel #12
0
 def setUp(self):
     """ overrides the setUp fixture of the superclass. """
     self.knight = Knight(name='Foo')
     self.enemy = OrcRider()