Exemplo n.º 1
0
    def test_play(self):
        """Unit test to verify AttackOfTheOrcs.play method."""
        print("\nCalling test_wargame.test_play..")
        game = AttackOfTheOrcs()
        self.hut_selection_counter = 0
        # Python 2.7 compatibility : replace builtins.input with raw_input
        # TODO: Note that this patching technique does NOT work in Python 2.7
        # It still seems to prompt the user input when the test is run.
        with mock.patch('__builtin__.raw_input',
                        new=self.user_input_processor):

            game.play()
            # Create a list that collects information on whether the
            # huts are acquired. It is a boolean list
            acquired_hut_list = [h.is_acquired for h in game.huts]

            # Player wins if all huts are acquired AND the player health
            # is grater than 0.
            if all(acquired_hut_list):
                # All the huts are acquired (winning criteria).
                # check the player's health!
                self.assertTrue(game.player.health_meter > 0)
            else:
                # This is the losing criteria., Player health can not be
                # positive when he/she loses.
                self.assertFalse(game.player.health_meter > 0)
Exemplo n.º 2
0
    def test_occupy_huts(self):
        game = AttackOfTheOrcs()
        game.setup_game_scenario()

        # Veryfi that only 5 huts are created
        self.assertEqual(len(game.huts), 5)

        # Huts occupants must be an instance of the Knight or OrcRider
        # or it could be set to None
        for hut in game.huts:
            assert ((hut.occupant is None)
                    or isinstance(hut.occupant, AbstractGameUnit))
Exemplo n.º 3
0
    def test_occupy_huts(self):
        """Jedinicni test za provjeru broja kućica i okupanata"""
        game = AttackOfTheOrcs()
        game.setup_game_scenario()

        # provjeri da je samo 5 kućica
        self.assertEqual(len(game.huts), 5)

        # okupanti kućice moraju biti instance klase GameUnit ili OrcRider
        for hut in game.huts:
            assert ((hut.occupant is None)
                    or isinstance(hut.occupant, GameUnit))
Exemplo n.º 4
0
    def test_play(self):
        """Jedinicni test za provjeru unosa u `play` metodi"""
        game = AttackOfTheOrcs()
        self.hut_selection_counter = 0
        with mock.patch('builtins.input',
                        new=self.user_input_processor) as foo_patch:
            foo_patch = self.user_input_processor
            game.play()
            # prikupi listu okupiranih kućica
            acquired_hut_list = [h.is_acquired for h in game.huts]

            # igrac pobjedjuje ako je osvojio sve kućice
            if all(acquired_hut_list):
                # kriterij za pobjedu
                self.assertTrue(game.player.health_meter > 0)
            else:
                # kriterij za gubljenje: igračevo zdravlje ne može biti >0
                self.assertFalse(game.player.health_meter > 0)
Exemplo n.º 5
0
    def test_play(self):
        """Unit test to veryfy AttackOfTheOrcs
        """
        game = AttackOfTheOrcs()
        self.hut_selection_counter = 0
        #Zastepowanie wbudowanej funkcji 'input' nasza funkcja
        with mock.patch('builtins.input', new=self.user_input_processor):
            game.play()

            #Create a list that collects information on whether the huts are acquired. Boolean list
            acquired_hut_list = [h.is_acquired for h in game.huts]

            #Player wins if all huts are acquired AND the player health is greather than 0
            if all(acquired_hut_list):
                #All the huts are acquired (winning criteria)
                #check the player's health!
                self.assertTrue(game.player.health_meter > 0)
            else:
                #Losing criteria. Player health can not be positive when he losses
                self.assertFalse(game.player.health_meter > 0)
Exemplo n.º 6
0
    def test_play(self):
        """Unit test to verify AttackOftheOrcs"""
        game = AttackOfTheOrcs()
        self.hut_selection_counter = 0
        with mock.patch('builtins.input', new=self.user_input_processor):
            game.play()
            # Create list that collects information on whether the
            # huts are acquired. It is a boolean list
            acquired_hut_list = [h.is_acquired for h in game.huts]

            # Player wins if all huts are acquired and the player health
            # is greater than zero
            if all(acquired_hut_list):
                # all huts are acquired (winning criteria)
                # check the player health
                self.assertTrue(game.player.health_meter > 0)
            else:
                # this is the losing criteria Player health cannot be
                # positive when he/she loses
                self.assertFalse(game.player.health_meter > 0)
Exemplo n.º 7
0
    def test_play(self):
        """Unit test to verify AttackOfTheOrcs.play method."""
        print("\nCalling test_wargame.test_play..")
        game = AttackOfTheOrcs()
        self.hut_selection_counter = 0
        with mock.patch('builtins.input', new=self.user_input_processor):
            game.play()
            # Create a list that collects information on whether the
            # huts are acquired. It is a boolean list
            acquired_hut_list = [h.is_acquired for h in game.huts]

            # Player wins if all huts are acquired AND the player health
            # is grater than 0.
            if all(acquired_hut_list):
                # All the huts are acquired (winning criteria).
                # check the player's health!
                self.assertTrue(game.player.health_meter > 0)
            else:
                # This is the losing criteria., Player health can not be
                # positive when he/she loses.
                self.assertFalse(game.player.health_meter > 0)
Exemplo n.º 8
0
    def test_occupy_huts(self):
        """Unittest to verify the number of huts and the occupants.

        This test verifies that the total number of `hut` instance is created
        and also checks the type of its `occupant` attribute.

        .. seealso::

            :py:meth: `attackoftheorcs.AttackOfTheOrcs._occupy_huts`,
            :py:meth: `attackoftheorcs.AttackOfTheOrcs.setup_game_scenario
        """
        print("\nCalling test_wargame.test_occupy_huts..")
        game = AttackOfTheOrcs()
        game.setup_game_scenario()

        # Verify that only 5 huts are created.
        self.assertEqual(len(game.huts), 5)

        # Huts occupants must be an instance of a Knight or OrcRider
        # otherwise is set to None.
        for hut in game.huts:
            assert(isinstance(hut.occupant, AbstractGameUnit) or hut.occupant is None)