private static void TestBoxName( PKMN.PokemonBox box ) { int generation = Util.GameToGeneration(box.Game); if (generation == 1) { // The getter shouldn't throw by convention, but the setter will. Assert.AreEqual(box.Name, ""); Assert.Throws <ApplicationException>( delegate { box.Name = "ABCDEFGH"; } ); } else { Assert.Throws <ArgumentOutOfRangeException>( delegate { box.Name = "ABCDEFGHI"; } ); box.Name = "ABCDEFGH"; Assert.AreEqual(box.Name, "ABCDEFGH"); } }
private static void TestEmptyPokemonBox( PKMN.PokemonBox box ) { for (int i = 0; i < box.Length; ++i) { Assert.AreEqual(box[i].Species, PKMN.Species.NONE); Assert.AreEqual(box[i].Game, box.Game); for (int j = 0; j < box[i].Moves.Count; ++j) { Assert.AreEqual(box[i].Moves[j].Move, PKMN.Move.NONE); Assert.AreEqual(box[i].Moves[j].PP, 0); } } // Make sure trying to get a Pokémon at an invalid index fails. Assert.Throws <IndexOutOfRangeException>( delegate { PKMN.Pokemon pokemon = box[-1]; } ); Assert.Throws <IndexOutOfRangeException>( delegate { PKMN.Pokemon pokemon = box[box.Length]; } ); }
private static void RandomizePokemon( PKMN.GameSave gameSave, PKMN.ItemEnumList itemList ) { PKMN.Game game = gameSave.Game; PKMN.MoveEnumList moveList = PKMN.Database.Lists.MoveList(game); PKMN.SpeciesEnumList pokemonList = PKMN.Database.Lists.PokemonList(1, true); PKMN.PokemonParty party = gameSave.PokemonParty; for (int i = 0; i < 6; ++i) { party[i] = Util.GetRandomPokemon(game, itemList, moveList, pokemonList); } PKMN.PokemonPC PC = gameSave.PokemonPC; for (int i = 0; i < PC.Length; ++i) { PKMN.PokemonBox box = PC[i]; for (int j = 0; j < box.Length; ++j) { box[j] = Util.GetRandomPokemon(game, itemList, moveList, pokemonList); } } }
public static void TestPokemonBox( PKMN.PokemonBox box, PKMN.Game[] validOtherGames, PKMN.Game invalidOtherGame ) { TestEmptyPokemonBox(box); TestBoxName(box); TestSettingPokemon(box, validOtherGames, invalidOtherGame); }
private static void TestSettingPokemon( PKMN.PokemonBox box, PKMN.Game[] validOtherGames, PKMN.Game invalidOtherGame ) { int generation = Util.GameToGeneration(box.Game); PKMN.Pokemon originalFirst = box[0]; PKMN.Pokemon originalSecond = box[1]; // Make sure we can't set Pokémon at invalid indices. Assert.Throws <IndexOutOfRangeException>( delegate { box[-1] = originalFirst; } ); Assert.Throws <IndexOutOfRangeException>( delegate { box[box.Length] = originalSecond; } ); // Create Pokémon and place in box. The original variables should // still have the same underlying Pokémon. PKMN.Pokemon bulbasaur = new PKMN.Pokemon(PKMN.Species.BULBASAUR, box.Game, "", 5); PKMN.Pokemon charmander = new PKMN.Pokemon(PKMN.Species.CHARMANDER, box.Game, "", 5); PKMN.Pokemon squirtle = new PKMN.Pokemon(PKMN.Species.SQUIRTLE, box.Game, "", 5); box[0] = bulbasaur; Assert.AreEqual(box.NumPokemon, 1); box[1] = charmander; Assert.AreEqual(box.NumPokemon, 2); // Replace one of the new ones. box[0] = squirtle; Assert.AreEqual(box.NumPokemon, 2); // Copy a Pokémon already part of the box. box[2] = box[1]; Assert.AreEqual(box.NumPokemon, 3); // We should always be able to clear the last contiguous Pokémon. box[2] = originalFirst; Assert.AreEqual(box.NumPokemon, 2); Assert.AreEqual(box[2].Species, PKMN.Species.NONE); // Put it back. box[2] = box[1]; Assert.AreEqual(box.NumPokemon, 3); // Check that Pokémon can be placed non-contiguously in the correct games. if (generation <= 2) { Assert.Throws <ArgumentOutOfRangeException>( delegate { box[1] = originalFirst; } ); Assert.AreEqual(box.NumPokemon, 3); Assert.AreEqual(box[1].Species, PKMN.Species.CHARMANDER); Assert.Throws <IndexOutOfRangeException>( delegate { box[4] = bulbasaur; } ); Assert.AreEqual(box.NumPokemon, 3); Assert.AreEqual(box[4].Species, PKMN.Species.NONE); } else { box[1] = originalFirst; Assert.AreEqual(box.NumPokemon, 2); Assert.AreEqual(box[1].Species, PKMN.Species.NONE); box[4] = bulbasaur; Assert.AreEqual(box.NumPokemon, 3); Assert.AreEqual(box[4].Species, PKMN.Species.BULBASAUR); // Restore it to how it was. box[1] = charmander; box[4] = originalFirst; Assert.AreEqual(box.NumPokemon, 3); Assert.AreEqual(box[1].Species, PKMN.Species.CHARMANDER); Assert.AreEqual(box[4].Species, PKMN.Species.NONE); } // Now check everything we've created. Each variable should have // the same underlying Pokémon. Assert.AreEqual(box[0].Species, PKMN.Species.SQUIRTLE); Assert.AreEqual(box[1].Species, PKMN.Species.CHARMANDER); Assert.AreEqual(box[2].Species, PKMN.Species.CHARMANDER); Assert.AreEqual(originalFirst.Species, PKMN.Species.NONE); Assert.AreEqual(originalSecond.Species, PKMN.Species.NONE); Assert.AreEqual(bulbasaur.Species, PKMN.Species.BULBASAUR); Assert.AreEqual(charmander.Species, PKMN.Species.CHARMANDER); Assert.AreEqual(squirtle.Species, PKMN.Species.SQUIRTLE); // Make sure converting Pokémon before putting them in the box works (or doesn't) // as expected. foreach (PKMN.Game validGame in validOtherGames) { PKMN.Pokemon pikachu = new PKMN.Pokemon( PKMN.Species.PIKACHU, validGame, "", 50 ); Assert.AreEqual(validGame, pikachu.Game); box[3] = pikachu; Assert.AreEqual(PKMN.Species.PIKACHU, box[3].Species); Assert.AreEqual(box.Game, box[3].Game); Assert.AreEqual(50, box[3].Level); } PKMN.Pokemon invalidPikachu = new PKMN.Pokemon( PKMN.Species.PIKACHU, invalidOtherGame, "", 50 ); Assert.Throws <ArgumentOutOfRangeException>( delegate { box[3] = invalidPikachu; } ); }
public static void CompareGameSaves( PKMN.GameSave save1, PKMN.GameSave save2 ) { PKMN.Game game = save1.Game; int generation = Util.GameToGeneration(game); Assert.AreEqual(save1.Game, save2.Game); Assert.AreEqual(save1.TrainerName, save2.TrainerName); Assert.AreEqual(save1.TrainerID, save2.TrainerID); Assert.AreEqual(save1.TrainerPublicID, save2.TrainerPublicID); if (!IsGBGame(game)) { Assert.AreEqual(save1.TrainerSecretID, save2.TrainerSecretID); } if (!IsMaleOnly(game)) { Assert.AreEqual(save1.TrainerGender, save2.TrainerGender); } if (!IsRivalNameSet(game)) { Assert.AreEqual(save1.RivalName, save2.RivalName); } Assert.AreEqual(save1.Money, save2.Money); Assert.AreEqual(save1.ItemBag.Count, save2.ItemBag.Count); foreach (string pocketName in save1.ItemBag.PocketNames) { CompareItemLists( save1.ItemBag[pocketName], save2.ItemBag[pocketName] ); } if (generation <= 3) { CompareItemLists( save1.ItemPC, save2.ItemPC ); } Assert.AreEqual(save1.PokemonParty.NumPokemon, save2.PokemonParty.NumPokemon); for (int i = 0; i < 6; ++i) { Util.ComparePokemon( save1.PokemonParty[i], save2.PokemonParty[i] ); } PKMN.PokemonPC pokemonPC1 = save1.PokemonPC; PKMN.PokemonPC pokemonPC2 = save2.PokemonPC; if (generation >= 2) { Assert.AreEqual(pokemonPC1.BoxNames.Count, pokemonPC2.BoxNames.Count); for (int i = 0; i < pokemonPC1.BoxNames.Count; ++i) { Assert.AreEqual(pokemonPC1.BoxNames[i], pokemonPC2.BoxNames[i]); } } for (int i = 0; i < pokemonPC1.Length; ++i) { PKMN.PokemonBox pokemonBox1 = pokemonPC1[i]; PKMN.PokemonBox pokemonBox2 = pokemonPC2[i]; if (generation >= 2) { Assert.AreEqual(pokemonBox1.Name, pokemonBox2.Name); } Assert.AreEqual(pokemonBox1.NumPokemon, pokemonBox2.NumPokemon); for (int j = 0; j < pokemonBox1.NumPokemon; ++j) { Util.ComparePokemon( pokemonBox1[j], pokemonBox2[j] ); } } if (!IsGameGamecube(game)) { ComparePokedexes( save1.Pokedex, save2.Pokedex ); } Assert.AreEqual(save1.NumericAttributes.Names, save2.NumericAttributes.Names); foreach (string attributeName in save1.NumericAttributes.Names) { Assert.AreEqual( save1.NumericAttributes[attributeName], save2.NumericAttributes[attributeName] ); } Assert.AreEqual(save1.StringAttributes.Names, save2.StringAttributes.Names); foreach (string attributeName in save1.StringAttributes.Names) { Assert.AreEqual( save1.StringAttributes[attributeName], save2.StringAttributes[attributeName] ); } Assert.AreEqual(save1.BooleanAttributes.Names, save2.BooleanAttributes.Names); foreach (string attributeName in save1.BooleanAttributes.Names) { Assert.AreEqual( save1.BooleanAttributes[attributeName], save2.BooleanAttributes[attributeName] ); } }
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); }