コード例 #1
0
    def create_member(self,
                      member_type: str,
                      pokedex_num: int,
                      source: str,
                      nickname: str = None,
                      item: str = None,
                      ability: str = None,
                      json: Dict = None) -> int:
        """ Adds a member (egg or Pokemon) to the player's _pc.

        Depending on the type of member, this function adds a new entry to the player's party. It also assigns the
        Pokemon an ID, and then increments it by 1 so that it is unique for the next member that is added.

        :param member_type: The party member type, either "Egg" or "Pokemon"
        :param pokedex_num: The Pokedex number that corresponds with the Pokemon species.
        :param source: The location that the Pokemon/Egg was acquired.
        :param nickname: The given name for the Pokemon.
        :param item: The item that the Pokemon is currently holding.
        :param ability: The Pokemon's special ability.
        :return: No return
        :rtype: None

        """
        self._validate_pokedex_number(pokedex_num)

        if not nickname:
            nickname = self._POKEDEX[pokedex_num][0]

        if member_type == Pokemon.member_type():
            self._pc_pokemon[self._ID] = Pokemon(self._ID,
                                                 pokedex_num,
                                                 source,
                                                 nickname=nickname,
                                                 item=item,
                                                 ability=ability,
                                                 json=json)
            self._ID += 1
        elif member_type == Egg.member_type():
            self._pc_pokemon[self._ID] = Egg(self._ID,
                                             pokedex_num,
                                             source,
                                             nickname=nickname,
                                             item=item,
                                             json=json)
            self._ID += 1
        else:
            raise ValueError(f"{member_type} is not a valid Party Member type")

        self._write_to_file()
        return self._ID - 1
コード例 #2
0
class EggTestClass(unittest.TestCase):
    _ID = 1

    def setUp(self):
        random.seed(13)
        self.egg = Egg(self._ID, 7, "Calgary", nickname="Flyboy")
        # print(self.egg.steps_remaining, self.egg.steps_required)

    def test_constructor(self):
        self.assertIsInstance(self.egg, Egg)

        with self.assertRaises(ValueError):
            e = Egg(self._ID, -1, "Calgary")

        with self.assertRaises(TypeError):
            e = Egg(self._ID, 6, 2)

    def test_steps_required(self):
        self.assertEqual(self.egg.steps_required, 3801)
        self.egg.add_steps(1)
        self.assertEqual(self.egg.steps_required, 3801)

    def test_steps_remaining(self):
        self.assertEqual(self.egg.steps_remaining, 3801)
        self.egg.add_steps(1)
        self.assertEqual(self.egg.steps_remaining, 3800)

    def test_add_steps(self):
        steps_remaining = self.egg.steps_remaining
        self.egg.add_steps(10)
        self.assertEqual(self.egg.steps_remaining, steps_remaining - 10)

        self.egg.add_steps(steps_remaining)
        self.assertTrue(self.egg.hatched)

    def test_description(self):
        print(self.egg.height, self.egg._weight)
        self.assertEqual(
            self.egg.description,
            "Your Flyboy is 1053.07cm tall and 296.06kg. Not currently in party"
        )

    def test_hatched(self):
        self.egg.add_steps(self.egg.steps_remaining)
        self.assertTrue(self.egg.hatched)

    def test_member_type(self):
        self.assertEqual(self.egg.member_type(), "Egg")

    def test_to_dict(self):
        egg_dict = self.egg.to_dict()

        test_dict = {
            "id": self.egg.id,
            "member_type": self.egg.member_type(),
            "pokedex_num": self.egg.pokedex_num,
            "source": self.egg.source,
            "nickname": self.egg.nickname,
            "item": None,
            "in_party": self.egg.in_party,
            "weight": self.egg.weight,
            "height": self.egg.height,
            "date_acquired": str(self.egg.date_acquired),
            "steps_required": self.egg.steps_required,
            "steps_remaining": self.egg.steps_remaining,
            "hatched": self.egg.hatched
        }

        self.assertEqual(egg_dict, test_dict)