public static void KeyItemPocketTest( PKMN.ItemList keyItemPocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); PKMN.Item keyItem = colosseum ? PKMN.Item.EIN_FILE_S : PKMN.Item.GONZAPS_KEY; int expectedLength = 43; // Check unchanging and initial values. Assert.AreEqual(keyItemPocket.Name, "Key Items"); Assert.AreEqual(keyItemPocket.Game, game); Assert.AreEqual(keyItemPocket.Length, expectedLength); Assert.AreEqual(keyItemPocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(keyItemPocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( keyItemPocket, keyItem ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.POTION, PKMN.Item.GREAT_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT } ); } else { ItemsTestsCommon.TestItemListInvalidItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.POTION, PKMN.Item.GREAT_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT, PKMN.Item.BATTLE_CD_01 } ); } // Confirm items from other generations can't be added. ItemsTestsCommon.TestItemListInvalidItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.GS_BALL, PKMN.Item.POFFIN_CASE, PKMN.Item.DNA_SPLICERS, PKMN.Item.AQUA_SUIT } ); // Confirm items from incompatible Generation III games can't be added. ItemsTestsCommon.TestItemListInvalidItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.HELIX_FOSSIL, PKMN.Item.TEA, PKMN.Item.RUBY } ); ItemsTestsCommon.TestItemListInvalidItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.MAGMA_EMBLEM, PKMN.Item.OLD_SEA_MAP } ); // Start adding and removing stuff, and make sure the numbers are accurate. if (colosseum) { ItemsTestsCommon.TestItemListSettingItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.JAIL_KEY, PKMN.Item.ELEVATOR_KEY, PKMN.Item.SMALL_TABLET, PKMN.Item.F_DISK, PKMN.Item.R_DISK, PKMN.Item.L_DISK, PKMN.Item.D_DISK, PKMN.Item.U_DISK } ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.JAIL_KEY, PKMN.Item.ELEVATOR_KEY, PKMN.Item.SMALL_TABLET, PKMN.Item.F_DISK, PKMN.Item.R_DISK, PKMN.Item.L_DISK, PKMN.Item.D_DISK, PKMN.Item.U_DISK } ); } else { ItemsTestsCommon.TestItemListSettingItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.KRANE_MEMO_1, PKMN.Item.KRANE_MEMO_2, PKMN.Item.KRANE_MEMO_3, PKMN.Item.KRANE_MEMO_4, PKMN.Item.KRANE_MEMO_5, PKMN.Item.VOICE_CASE_1, PKMN.Item.VOICE_CASE_2, PKMN.Item.VOICE_CASE_3 } ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( keyItemPocket, new PKMN.Item[] { PKMN.Item.KRANE_MEMO_1, PKMN.Item.KRANE_MEMO_2, PKMN.Item.KRANE_MEMO_3, PKMN.Item.KRANE_MEMO_4, PKMN.Item.KRANE_MEMO_5, PKMN.Item.VOICE_CASE_1, PKMN.Item.VOICE_CASE_2, PKMN.Item.VOICE_CASE_3 } ); } Assert.AreEqual(keyItemPocket.ValidItems.Count, keyItemPocket.ValidItemNames.Count); Assert.Greater(keyItemPocket.ValidItems.Count, 0); }
public static void BallPocketTest( PKMN.ItemList ballPocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); int expectedLength = 16; // Check unchanging and initial values. Assert.AreEqual(ballPocket.Name, "Poké Balls"); Assert.AreEqual(ballPocket.Game, game); Assert.AreEqual(ballPocket.Length, expectedLength); Assert.AreEqual(ballPocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(ballPocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( ballPocket, PKMN.Item.MASTER_BALL ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( ballPocket, new PKMN.Item[] { PKMN.Item.EIN_FILE_S, PKMN.Item.POTION, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT } ); } else { ItemsTestsCommon.TestItemListInvalidItems( ballPocket, new PKMN.Item[] { PKMN.Item.GONZAPS_KEY, PKMN.Item.POTION, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT, PKMN.Item.BATTLE_CD_01 } ); } // Confirm items from later generations can't be added. ItemsTestsCommon.TestItemListInvalidItems( ballPocket, new PKMN.Item[] { PKMN.Item.MOON_BALL, PKMN.Item.HEAL_BALL, PKMN.Item.DREAM_BALL } ); // Start adding and removing stuff, and make sure the numbers are accurate. PKMN.Item[] validItems = { PKMN.Item.MASTER_BALL, PKMN.Item.ULTRA_BALL, PKMN.Item.GREAT_BALL, PKMN.Item.POKE_BALL, PKMN.Item.SAFARI_BALL, PKMN.Item.NET_BALL, PKMN.Item.DIVE_BALL, PKMN.Item.NEST_BALL }; ItemsTestsCommon.TestItemListSettingItems( ballPocket, validItems ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( ballPocket, validItems ); Assert.AreEqual(ballPocket.ValidItems.Count, ballPocket.ValidItemNames.Count); Assert.Greater(ballPocket.ValidItems.Count, 0); }
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); }
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 ItemBagTest( PKMN.ItemBag itemBag, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); PKMN.Item keyItem = colosseum ? PKMN.Item.EIN_FILE_S : PKMN.Item.GONZAPS_KEY; // Check unchanging and initial values. Assert.AreEqual(itemBag.Game, game); Assert.AreEqual(itemBag.Count, (colosseum ? 6 : 7)); ItemPocketTest(itemBag["Items"], game); KeyItemPocketTest(itemBag["Key Items"], game); BallPocketTest(itemBag["Poké Balls"], game); TMPocketTest(itemBag["TMs"], game); BerryPocketTest(itemBag["Berries"], game); ColognePocketTest(itemBag["Colognes"], game); if (!colosseum) { BattleCDPocketTest(itemBag["Battle CDs"], game); } // Make sure adding items through the bag adds to the proper pockets. Assert.AreEqual(itemBag["Items"].NumItems, 0); Assert.AreEqual(itemBag["Key Items"].NumItems, 0); Assert.AreEqual(itemBag["Poké Balls"].NumItems, 0); Assert.AreEqual(itemBag["TMs"].NumItems, 0); Assert.AreEqual(itemBag["Berries"].NumItems, 0); Assert.AreEqual(itemBag["Colognes"].NumItems, 0); if (!colosseum) { Assert.AreEqual(itemBag["Battle CDs"].NumItems, 0); } foreach (PKMN.Item item in (colosseum ? ColosseumAllPocketItems : XDAllPocketItems)) { itemBag.Add(item, 5); } Assert.AreEqual(itemBag["Items"][0].Item, PKMN.Item.POTION); Assert.AreEqual(itemBag["Items"][0].Amount, 5); Assert.AreEqual(itemBag["Items"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Items"][1].Amount, 0); Assert.AreEqual(itemBag["Key Items"][0].Item, keyItem); Assert.AreEqual(itemBag["Key Items"][0].Amount, 5); Assert.AreEqual(itemBag["Key Items"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Key Items"][1].Amount, 0); Assert.AreEqual(itemBag["Poké Balls"][0].Item, PKMN.Item.GREAT_BALL); Assert.AreEqual(itemBag["Poké Balls"][0].Amount, 5); Assert.AreEqual(itemBag["Poké Balls"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Poké Balls"][1].Amount, 0); Assert.AreEqual(itemBag["TMs"][0].Item, PKMN.Item.TM01); Assert.AreEqual(itemBag["TMs"][0].Amount, 5); Assert.AreEqual(itemBag["TMs"][1].Item, PKMN.Item.TM02); Assert.AreEqual(itemBag["TMs"][1].Amount, 5); Assert.AreEqual(itemBag["TMs"][2].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["TMs"][2].Amount, 0); Assert.AreEqual(itemBag["Berries"][0].Item, PKMN.Item.ASPEAR_BERRY); Assert.AreEqual(itemBag["Berries"][0].Amount, 5); Assert.AreEqual(itemBag["Berries"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Berries"][1].Amount, 0); Assert.AreEqual(itemBag["Colognes"][0].Item, PKMN.Item.JOY_SCENT); Assert.AreEqual(itemBag["Colognes"][0].Amount, 5); if (colosseum) { Assert.AreEqual(itemBag["Colognes"][1].Item, PKMN.Item.EXCITE_SCENT); Assert.AreEqual(itemBag["Colognes"][1].Amount, 5); Assert.AreEqual(itemBag["Colognes"][2].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][2].Amount, 0); } else { Assert.AreEqual(itemBag["Colognes"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][1].Amount, 0); Assert.AreEqual(itemBag["Battle CDs"][0].Item, PKMN.Item.BATTLE_CD_01); Assert.AreEqual(itemBag["Battle CDs"][0].Amount, 5); } // Make sure removing items through the bag removes from the proper pockets. foreach (PKMN.Item item in (colosseum ? ColosseumAllPocketItems : XDAllPocketItems)) { itemBag.Remove(item, 5); } Assert.AreEqual(itemBag["Items"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Items"][0].Amount, 0); Assert.AreEqual(itemBag["Items"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Items"][1].Amount, 0); Assert.AreEqual(itemBag["Key Items"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Key Items"][0].Amount, 0); Assert.AreEqual(itemBag["Key Items"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Key Items"][1].Amount, 0); Assert.AreEqual(itemBag["Poké Balls"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Poké Balls"][0].Amount, 0); Assert.AreEqual(itemBag["Poké Balls"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Poké Balls"][1].Amount, 0); Assert.AreEqual(itemBag["TMs"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["TMs"][0].Amount, 0); Assert.AreEqual(itemBag["TMs"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["TMs"][1].Amount, 0); Assert.AreEqual(itemBag["TMs"][2].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["TMs"][2].Amount, 0); Assert.AreEqual(itemBag["Berries"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Berries"][0].Amount, 0); Assert.AreEqual(itemBag["Berries"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Berries"][1].Amount, 0); Assert.AreEqual(itemBag["Colognes"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][0].Amount, 0); if (colosseum) { Assert.AreEqual(itemBag["Colognes"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][1].Amount, 0); Assert.AreEqual(itemBag["Colognes"][2].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][2].Amount, 0); } else { Assert.AreEqual(itemBag["Colognes"][1].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Colognes"][1].Amount, 0); Assert.AreEqual(itemBag["Battle CDs"][0].Item, PKMN.Item.NONE); Assert.AreEqual(itemBag["Battle CDs"][0].Amount, 0); } ItemsTestsCommon.TestItemBagInvalidItems( itemBag, colosseum ? ColosseumWrongGameAllPocketItems : XDWrongGameAllPocketItems ); }
// Game Boy Advance public static void TestLoadingAndSaving3GPKM( PKMN.Game game ) { TestLoadingAndSaving(game, "3gpkm"); }
private static void TestTimePlayed( PKMN.GameSave gameSave ) { PKMN.Game game = gameSave.Game; int generation = Util.GameToGeneration(game); int milliseconds = 0; if (generation > 1) { // Generation I doesn't record to sub-second precision. milliseconds = rng.Next(0, 999); } System.TimeSpan validTimePlayed = new System.TimeSpan( 0, // Days rng.Next(0, 255), rng.Next(0, 59), rng.Next(0, 59), milliseconds ); if (IsGameGamecube(game)) { Assert.Throws <ApplicationException>( delegate { gameSave.TimePlayed = validTimePlayed; } ); Assert.Throws <ApplicationException>( delegate { System.TimeSpan timePlayed = gameSave.TimePlayed; } ); } else { // Test a valid time played. gameSave.TimePlayed = validTimePlayed; // Internally, time is stored with a precision of 1/60 second. Assert.That( gameSave.TimePlayed, Is.EqualTo(validTimePlayed).Within( System.TimeSpan.FromMilliseconds(1000.0 / 60.0) ) ); System.TimeSpan[] invalidTimeSpans = { new System.TimeSpan(0, -1, 0, 0, 0), new System.TimeSpan(0, 0, -1, 0, 0), new System.TimeSpan(0, 0, 0, -1, 0), // Just past the maximum internal storage size new System.TimeSpan(0, 65536, 0, 0, 0) }; foreach (System.TimeSpan invalidTimePlayed in invalidTimeSpans) { Assert.Throws <IndexOutOfRangeException>( delegate { gameSave.TimePlayed = invalidTimePlayed; } ); } } }
public static void ItemPocketTest( PKMN.ItemList itemPocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); int expectedLength = colosseum ? 20 : 30; // Check unchanging and initial values. Assert.AreEqual(itemPocket.Name, "Items"); Assert.AreEqual(itemPocket.Game, game); Assert.AreEqual(itemPocket.Length, expectedLength); Assert.AreEqual(itemPocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(itemPocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( itemPocket, PKMN.Item.POTION ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( itemPocket, new PKMN.Item[] { PKMN.Item.EIN_FILE_S, PKMN.Item.GREAT_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT } ); } else { ItemsTestsCommon.TestItemListInvalidItems( itemPocket, new PKMN.Item[] { PKMN.Item.GONZAPS_KEY, PKMN.Item.GREAT_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.BATTLE_CD_01 } ); } // Confirm items from other generations can't be added. ItemsTestsCommon.TestItemListInvalidItems( itemPocket, new PKMN.Item[] { PKMN.Item.PINK_BOW, PKMN.Item.BLACK_SLUDGE, PKMN.Item.BINDING_BAND, PKMN.Item.BEEDRILLITE } ); // Start adding and removing stuff, and make sure the numbers are accurate. PKMN.Item[] validItems = { PKMN.Item.POTION, PKMN.Item.ORANGE_MAIL, PKMN.Item.LAVA_COOKIE, PKMN.Item.STARDUST, PKMN.Item.SHADOW_MAIL, PKMN.Item.PINK_SCARF, PKMN.Item.ANTIDOTE, PKMN.Item.GREEN_SHARD }; ItemsTestsCommon.TestItemListSettingItems( itemPocket, validItems ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( itemPocket, validItems ); Assert.AreEqual(itemPocket.ValidItems.Count, itemPocket.ValidItemNames.Count); Assert.Greater(itemPocket.ValidItems.Count, 0); }
private static bool IsRivalNameSet( PKMN.Game game ) { return(Array.IndexOf(RIVAL_NAME_SET_GAMES, game) > -1); }
private static bool IsGameGamecube(PKMN.Game game) { return((game == PKMN.Game.COLOSSEUM) || (game == PKMN.Game.XD)); }
private static bool IsMaleOnly( PKMN.Game game ) { return(Array.IndexOf(MALE_ONLY_GAMES, game) > -1); }
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] ); } }
/* * Utility functions */ private static bool IsGBGame( PKMN.Game game ) { return(Util.GameToGeneration(game) <= 2); }
public static void TMPocketTest( PKMN.ItemList tmPocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); int expectedLength = 64; // Check unchanging and initial values. Assert.AreEqual(tmPocket.Name, "TMs"); Assert.AreEqual(tmPocket.Game, game); Assert.AreEqual(tmPocket.Length, expectedLength); Assert.AreEqual(tmPocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(tmPocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( tmPocket, PKMN.Item.TM01 ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( tmPocket, new PKMN.Item[] { PKMN.Item.EIN_FILE_S, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT } ); } else { ItemsTestsCommon.TestItemListInvalidItems( tmPocket, new PKMN.Item[] { PKMN.Item.GONZAPS_KEY, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.ORAN_BERRY, PKMN.Item.JOY_SCENT, PKMN.Item.BATTLE_CD_01 } ); } // Confirm items from later generations can't be added. ItemsTestsCommon.TestItemListInvalidItems( tmPocket, new PKMN.Item[] { PKMN.Item.TM51, PKMN.Item.HM01 } ); // Start adding and removing stuff, and make sure the numbers are accurate. PKMN.Item[] validItems = { PKMN.Item.TM01, PKMN.Item.TM02, PKMN.Item.TM03, PKMN.Item.TM04, PKMN.Item.TM05, PKMN.Item.TM06, PKMN.Item.TM07, PKMN.Item.TM08 }; ItemsTestsCommon.TestItemListSettingItems( tmPocket, validItems ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( tmPocket, validItems ); Assert.AreEqual(tmPocket.ValidItems.Count, tmPocket.ValidItemNames.Count); Assert.AreEqual(tmPocket.ValidItems.Count, 50); }
public void TestSavingAndLoadingPK3( PKMN.Game game ) { PKMNTest.PokemonIOTests.TestLoadingAndSavingPK3(game); }
public static void BerryPocketTest( PKMN.ItemList berryPocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); int expectedLength = 46; // Check unchanging and initial values. Assert.AreEqual(berryPocket.Name, "Berries"); Assert.AreEqual(berryPocket.Game, game); Assert.AreEqual(berryPocket.Length, expectedLength); Assert.AreEqual(berryPocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(berryPocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( berryPocket, PKMN.Item.RAZZ_BERRY ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( berryPocket, new PKMN.Item[] { PKMN.Item.EIN_FILE_S, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.TM01, PKMN.Item.JOY_SCENT } ); } else { ItemsTestsCommon.TestItemListInvalidItems( berryPocket, new PKMN.Item[] { PKMN.Item.GONZAPS_KEY, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.TM01, PKMN.Item.JOY_SCENT, PKMN.Item.BATTLE_CD_01 } ); } // Confirm items from later generations can't be added. ItemsTestsCommon.TestItemListInvalidItems( berryPocket, new PKMN.Item[] { PKMN.Item.BERRY, PKMN.Item.OCCA_BERRY, PKMN.Item.ROSELI_BERRY } ); // Start adding and removing stuff, and make sure the numbers are accurate. PKMN.Item[] validItems = { PKMN.Item.CHERI_BERRY, PKMN.Item.RAZZ_BERRY, PKMN.Item.LUM_BERRY, PKMN.Item.PINAP_BERRY, PKMN.Item.ASPEAR_BERRY, PKMN.Item.IAPAPA_BERRY, PKMN.Item.WIKI_BERRY, PKMN.Item.APICOT_BERRY }; ItemsTestsCommon.TestItemListSettingItems( berryPocket, validItems ); ItemsTestsCommon.TestItemListAddingAndRemovingItems( berryPocket, validItems ); Assert.AreEqual(berryPocket.ValidItems.Count, berryPocket.ValidItemNames.Count); Assert.Greater(berryPocket.ValidItems.Count, 0); }
public void FormTest( PKMN.Game game ) { PKMNTest.PokemonTestCommon.FormTest(game); }
public static void ColognePocketTest( PKMN.ItemList colognePocket, PKMN.Game game ) { bool colosseum = (game == PKMN.Game.COLOSSEUM); int expectedLength = 3; // Check unchanging and initial values. Assert.AreEqual(colognePocket.Name, "Colognes"); Assert.AreEqual(colognePocket.Game, game); Assert.AreEqual(colognePocket.Length, expectedLength); Assert.AreEqual(colognePocket.NumItems, 0); // Make sure item slots start as correctly empty. ItemsTestsCommon.TestItemListEmptySlots(colognePocket); // Confirm exceptions are thrown when expected. ItemsTestsCommon.TestItemListIndexOutOfRangeException( colognePocket, PKMN.Item.JOY_SCENT ); // Confirm items from other pockets can't be added. if (colosseum) { ItemsTestsCommon.TestItemListInvalidItems( colognePocket, new PKMN.Item[] { PKMN.Item.EIN_FILE_S, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY } ); } else { ItemsTestsCommon.TestItemListInvalidItems( colognePocket, new PKMN.Item[] { PKMN.Item.GONZAPS_KEY, PKMN.Item.POTION, PKMN.Item.MASTER_BALL, PKMN.Item.TM01, PKMN.Item.ORAN_BERRY, PKMN.Item.BATTLE_CD_01 } ); } colognePocket.Add(PKMN.Item.JOY_SCENT, 3); colognePocket.Add(PKMN.Item.EXCITE_SCENT, 3); colognePocket.Add(PKMN.Item.VIVID_SCENT, 3); colognePocket.Remove(PKMN.Item.EXCITE_SCENT, 3); colognePocket.Remove(PKMN.Item.VIVID_SCENT, 1); Assert.AreEqual(colognePocket[0].Item, PKMN.Item.JOY_SCENT); Assert.AreEqual(colognePocket[0].Amount, 3); Assert.AreEqual(colognePocket[1].Item, PKMN.Item.VIVID_SCENT); Assert.AreEqual(colognePocket[1].Amount, 2); Assert.AreEqual(colognePocket[2].Item, PKMN.Item.NONE); Assert.AreEqual(colognePocket[2].Amount, 0); colognePocket.Remove(PKMN.Item.JOY_SCENT, 3); colognePocket.Remove(PKMN.Item.VIVID_SCENT, 2); Assert.AreEqual(colognePocket[0].Item, PKMN.Item.NONE); Assert.AreEqual(colognePocket[0].Amount, 0); Assert.AreEqual(colognePocket[1].Item, PKMN.Item.NONE); Assert.AreEqual(colognePocket[1].Amount, 0); Assert.AreEqual(colognePocket[2].Item, PKMN.Item.NONE); Assert.AreEqual(colognePocket[2].Amount, 0); Assert.AreEqual(colognePocket.ValidItems.Count, colognePocket.ValidItemNames.Count); Assert.AreEqual(colognePocket.ValidItems.Count, 3); }
public void GenderTest( PKMN.Game game ) { PKMNTest.PokemonTestCommon.GenderTest(game); }
// Generation III public static void TestLoadingAndSavingPK2( PKMN.Game game ) { TestLoadingAndSaving(game, "pk2"); }
public void Gen3UnownTest( PKMN.Game game ) { PKMNTest.UnownTests.Gen3UnownTest(game); }
public static void TestLoadingAndSavingXK3( PKMN.Game game ) { TestLoadingAndSaving(game, "xk3"); }
private static void TestSettingPokemon( PKMN.PokemonParty party, PKMN.Game[] validOtherGames, PKMN.Game invalidOtherGame ) { PKMN.Pokemon originalFirst = party[0]; PKMN.Pokemon originalSecond = party[1]; // Make sure we can't set Pokémon at invalid indices. Assert.Throws <IndexOutOfRangeException>( delegate { party[-1] = originalFirst; } ); Assert.Throws <IndexOutOfRangeException>( delegate { party[party.Length] = originalSecond; } ); // Create Pokémon and place in party. The original variables should // still have the same underlying Pokémon. PKMN.Pokemon bulbasaur = new PKMN.Pokemon(PKMN.Species.BULBASAUR, party.Game, "", 5); PKMN.Pokemon charmander = new PKMN.Pokemon(PKMN.Species.CHARMANDER, party.Game, "", 5); PKMN.Pokemon squirtle = new PKMN.Pokemon(PKMN.Species.SQUIRTLE, party.Game, "", 5); party[0] = bulbasaur; Assert.AreEqual(1, party.NumPokemon); Assert.AreEqual(PKMN.Species.BULBASAUR, party[0].Species); party[1] = charmander; Assert.AreEqual(2, party.NumPokemon); Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species); // Replace one of the new ones. party[0] = squirtle; Assert.AreEqual(2, party.NumPokemon); Assert.AreEqual(PKMN.Species.SQUIRTLE, party[0].Species); // Copy a Pokémon already part of the party. party[2] = party[1]; Assert.AreEqual(3, party.NumPokemon); Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species); // We should be able to clear the last contiguous Pokémon. party[2] = originalFirst; Assert.AreEqual(2, party.NumPokemon); Assert.AreEqual(PKMN.Species.NONE, party[2].Species); // Put it back. party[2] = party[1]; Assert.AreEqual(3, party.NumPokemon); Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species); // Check that Pokémon cannot be placed non-contiguously. Assert.Throws <ArgumentOutOfRangeException>( delegate { party[1] = originalFirst; } ); Assert.AreEqual(3, party.NumPokemon); Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species); Assert.Throws <IndexOutOfRangeException>( delegate { party[4] = bulbasaur; } ); Assert.AreEqual(3, party.NumPokemon); Assert.AreEqual(PKMN.Species.NONE, party[4].Species); // Now check everything we've created. Each variable should have // the same underlying Pokémon. Assert.AreEqual(PKMN.Species.SQUIRTLE, party[0].Species); Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species); Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species); Assert.AreEqual(PKMN.Species.NONE, originalFirst.Species); Assert.AreEqual(PKMN.Species.NONE, originalSecond.Species); Assert.AreEqual(PKMN.Species.BULBASAUR, bulbasaur.Species); Assert.AreEqual(PKMN.Species.CHARMANDER, charmander.Species); Assert.AreEqual(PKMN.Species.SQUIRTLE, squirtle.Species); // Make sure converting Pokémon before putting them in the party 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); party[3] = pikachu; Assert.AreEqual(PKMN.Species.PIKACHU, party[3].Species); Assert.AreEqual(party.Game, party[3].Game); Assert.AreEqual(50, party[3].Level); } PKMN.Pokemon invalidPikachu = new PKMN.Pokemon( PKMN.Species.PIKACHU, invalidOtherGame, "", 50 ); Assert.Throws <ArgumentOutOfRangeException>( delegate { party[3] = invalidPikachu; } ); }