コード例 #1
0
ファイル: GameSaveTest.cs プロジェクト: ncorgan/libpkmn
 private static void ComparePokedexes(
     PKMN.Pokedex pokedex1,
     PKMN.Pokedex pokedex2
     )
 {
     Assert.AreEqual(pokedex1.AllSeen, pokedex2.AllSeen);
     Assert.AreEqual(pokedex1.AllCaught, pokedex2.AllCaught);
 }
コード例 #2
0
    public void PokedexHelpersTest()
    {
        PKMN.Pokedex pokedex = new PKMN.Pokedex(PKMN.Game.RUBY);

        // The Pokemon class and its helpers all use the underlying pointer
        // in generating their hash codes. Make sure these aren't equal.

        Assert.AreNotEqual(pokedex.GetHashCode(), pokedex.SeenPokemonMap.GetHashCode());
        Assert.AreNotEqual(pokedex.GetHashCode(), pokedex.CaughtPokemonMap.GetHashCode());
        Assert.AreNotEqual(pokedex.SeenPokemonMap.GetHashCode(), pokedex.CaughtPokemonMap.GetHashCode());
    }
コード例 #3
0
        public static void TestPokedex(
            PKMN.Pokedex pokedex
            )
        {
            int generation = Util.GameToGeneration(pokedex.Game);

            // Test initial values.

            Assert.AreEqual(0, pokedex.NumSeen);
            Assert.AreEqual(0, pokedex.AllSeen.Count);
            Assert.AreEqual(0, pokedex.NumCaught);
            Assert.AreEqual(0, pokedex.AllCaught.Count);

            // Set random Pokémon to be seen and caught.

            PKMN.SpeciesEnumList allPokemon = PKMN.Database.Lists.PokemonList(generation, true);
            int numSeen   = rng.Next(0, allPokemon.Count);
            int numCaught = rng.Next(0, allPokemon.Count);

            PKMN.IntList allSeenNums = new PKMN.IntList();
            while (allSeenNums.Count < numSeen)
            {
                int index = rng.Next(0, allPokemon.Count);
                if (allSeenNums.IndexOf(index) == -1)
                {
                    allSeenNums.Add(index);

                    PKMN.Species species = allPokemon[index];
                    pokedex.SeenPokemonMap[species] = true;
                    Assert.IsTrue(pokedex.SeenPokemonMap[species]);
                }
            }
            Assert.AreEqual(allSeenNums.Count, pokedex.NumSeen);
            Assert.AreEqual(allSeenNums.Count, pokedex.AllSeen.Count);

            PKMN.IntList allCaughtNums = new PKMN.IntList();
            while (allCaughtNums.Count < numCaught)
            {
                int index = rng.Next(0, allPokemon.Count);
                if (allCaughtNums.IndexOf(index) == -1)
                {
                    allCaughtNums.Add(index);

                    PKMN.Species species = allPokemon[index];
                    pokedex.CaughtPokemonMap[species] = true;
                    Assert.IsTrue(pokedex.CaughtPokemonMap[species]);
                }
            }
            Assert.AreEqual(allCaughtNums.Count, pokedex.NumCaught);
            Assert.AreEqual(allCaughtNums.Count, pokedex.AllCaught.Count);

            // Remove all entries.

            foreach (PKMN.Species species in pokedex.AllSeen)
            {
                pokedex.SeenPokemonMap[species] = false;
                Assert.IsFalse(pokedex.SeenPokemonMap[species]);
            }
            Assert.AreEqual(0, pokedex.NumSeen);
            Assert.AreEqual(0, pokedex.AllSeen.Count);

            foreach (PKMN.Species species in pokedex.AllCaught)
            {
                pokedex.CaughtPokemonMap[species] = false;
                Assert.IsFalse(pokedex.CaughtPokemonMap[species]);
            }
            Assert.AreEqual(0, pokedex.NumCaught);
            Assert.AreEqual(0, pokedex.AllCaught.Count);
        }
コード例 #4
0
ファイル: GameSaveTest.cs プロジェクト: ncorgan/libpkmn
        private static void TestCommonFields(
            PKMN.GameSave gameSave
            )
        {
            PKMN.Game game = gameSave.Game;

            // Trainer name
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                gameSave.TrainerName = "";
            }
                );
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                gameSave.TrainerName = "LibPKMNLibPKMN";
            }
                );
            gameSave.TrainerName = "LibPKMN";
            Assert.AreEqual(gameSave.TrainerName, "LibPKMN");

            // Trainer ID
            gameSave.TrainerID = IsGBGame(game) ? DEFAULT_TRAINER_PID : PKMN.Pokemon.DefaultTrainerID;
            TestTrainerID(gameSave);
            gameSave.TrainerPublicID = DEFAULT_TRAINER_PID;
            TestTrainerID(gameSave);
            if (IsGBGame(game))
            {
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerSecretID = DEFAULT_TRAINER_SID;
                }
                    );
            }
            else
            {
                gameSave.TrainerSecretID = DEFAULT_TRAINER_SID;
                TestTrainerID(gameSave);
            }

            // Rival Name
            if (IsRivalNameSet(game))
            {
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.RivalName = PKMN.Pokemon.DefaultTrainerName;
                }
                    );
            }
            else
            {
                gameSave.RivalName = PKMN.Pokemon.DefaultTrainerName;
                Assert.AreEqual(gameSave.RivalName, PKMN.Pokemon.DefaultTrainerName);
            }

            // Trainer Gender
            if (IsMaleOnly(game))
            {
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.MALE);
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.MALE;
                }
                    );
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.FEMALE;
                }
                    );
            }
            else
            {
                gameSave.TrainerGender = PKMN.Gender.MALE;
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.MALE);
                gameSave.TrainerGender = PKMN.Gender.FEMALE;
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.FEMALE);
                Assert.Throws <ArgumentOutOfRangeException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.GENDERLESS;
                }
                    );
            }

            // Money
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                gameSave.Money = -1;
            }
                );
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                gameSave.Money = MONEY_MAX + 1;
            }
                );
            gameSave.Money = 123456;
            Assert.AreEqual(gameSave.Money, 123456);

            // Pokémon Party
            PKMN.PokemonParty party = gameSave.PokemonParty;
            int numPokemon          = party.NumPokemon;

            Assert.AreEqual(party.Length, 6);

            Assert.Greater(numPokemon, 0);
            Assert.LessOrEqual(numPokemon, 6);
            for (int i = 0; i < 6; ++i)
            {
                if (i < numPokemon)
                {
                    Assert.AreNotEqual(party[i].Species, PKMN.Species.NONE);
                }
                else
                {
                    Assert.AreEqual(party[i].Species, PKMN.Species.NONE);
                }
            }

            // Pokémon PC
            PKMN.PokemonPC pokemonPC = gameSave.PokemonPC;
            for (int i = 0; i < pokemonPC.Length; ++i)
            {
                PKMN.PokemonBox box = pokemonPC[i];

                Assert.LessOrEqual(box.NumPokemon, box.Length);

                // Boxes are only contiguous in Game Boy games.
                if (IsGBGame(game))
                {
                    numPokemon = box.NumPokemon;
                    for (int j = 0; j < box.Length; ++j)
                    {
                        if (j < numPokemon)
                        {
                            Assert.AreNotEqual(box[j].Species, PKMN.Species.NONE);
                        }
                        else
                        {
                            Assert.AreEqual(box[j].Species, PKMN.Species.NONE);
                        }
                    }
                }
            }

            // Pokédex
            if (!IsGameGamecube(game))
            {
                PKMN.Pokedex pokedex = gameSave.Pokedex;
                Assert.GreaterOrEqual(pokedex.NumSeen, pokedex.NumCaught);

                for (int partyIndex = 0; partyIndex < party.Length; ++partyIndex)
                {
                    PKMN.Species species = party[partyIndex].Species;
                    if ((species != PKMN.Species.NONE) && !party[partyIndex].IsEgg)
                    {
                        Assert.IsTrue(pokedex.SeenPokemonMap[species]);
                        Assert.IsTrue(pokedex.CaughtPokemonMap[species]);
                    }
                }

                for (int PCIndex = 0; PCIndex < pokemonPC.Length; ++PCIndex)
                {
                    PKMN.PokemonBox box = pokemonPC[PCIndex];
                    for (int boxIndex = 0; boxIndex < box.Length; ++boxIndex)
                    {
                        PKMN.Species species = box[boxIndex].Species;
                        if ((species != PKMN.Species.NONE) && !box[boxIndex].IsEgg)
                        {
                            Assert.IsTrue(pokedex.SeenPokemonMap[species]);
                            Assert.IsTrue(pokedex.CaughtPokemonMap[species]);
                        }
                    }
                }

                // Make sure that when a Pokémon is added to the party or PC, it's
                // added to the Pokédex. Manually remove the test species from the
                // Pokédex to confirm this behavior.

                PKMN.Species testSpecies1 = PKMN.Species.BULBASAUR;
                PKMN.Species testSpecies2 = PKMN.Species.CHARMANDER;

                pokedex.SeenPokemonMap[testSpecies1] = false;
                Assert.IsFalse(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsFalse(pokedex.CaughtPokemonMap[testSpecies1]);

                pokedex.SeenPokemonMap[testSpecies2] = false;
                Assert.IsFalse(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsFalse(pokedex.CaughtPokemonMap[testSpecies1]);

                PKMN.Pokemon testPokemon1 = new PKMN.Pokemon(
                    testSpecies1,
                    game,
                    "",
                    5
                    );
                PKMN.Pokemon testPokemon2 = new PKMN.Pokemon(
                    testSpecies2,
                    game,
                    "",
                    5
                    );


                party[0] = testPokemon1;
                Assert.IsTrue(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsTrue(pokedex.CaughtPokemonMap[testSpecies1]);

                pokemonPC[0][0] = testPokemon2;
                Assert.IsTrue(pokedex.SeenPokemonMap[testSpecies2]);
                Assert.IsTrue(pokedex.CaughtPokemonMap[testSpecies2]);
            }

            TestTimePlayed(gameSave);
        }