From e735d92218d23a24761ac8553fe4d6ee0b9475be Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 12 Sep 2023 18:15:44 -0700 Subject: [PATCH] Generator Tests: Add tests for LGPE->SV Quite a few broken ctor's in the test result output pane, but these will be addressed later (Teal Mask DLC just dropped). --- .../Legality/LegalityTests.cs | 19 +--------- .../Simulator/GeneratorTests.cs | 38 +++++++++++++------ Tests/PKHeX.Core.Tests/Util/TestUtil.cs | 15 ++++++++ 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs index 45fc98978..5eb40e049 100644 --- a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs @@ -10,21 +10,7 @@ namespace PKHeX.Core.Tests.Legality; public class LegalityTest { private static readonly string TestPath = TestUtil.GetRepoPath(); - private static readonly object InitLock = new(); - private static bool IsInitialized; - - private static void Init() - { - lock (InitLock) - { - if (IsInitialized) - return; - RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons); - IsInitialized = true; - } - } - - static LegalityTest() => Init(); + static LegalityTest() => TestUtil.InitializeLegality(); [Theory] [InlineData("censor")] @@ -41,7 +27,6 @@ public class LegalityTest [InlineData("Illegal", false)] public void TestPublicFiles(string name, bool isValid) { - RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons); var folder = TestUtil.GetRepoPath(); folder = Path.Combine(folder, "Legality"); VerifyAll(folder, name, isValid); @@ -54,8 +39,6 @@ public class LegalityTest [InlineData("FalseFlags", false)] // legal quirks, to be fixed in the future public void TestPrivateFiles(string name, bool isValid) { - if (!isValid) - Init(); var folder = Path.Combine(TestPath, "Legality", "Private"); VerifyAll(folder, name, isValid, false); } diff --git a/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs b/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs index 8ae72cdb4..3c00a4421 100644 --- a/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs +++ b/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs @@ -9,28 +9,44 @@ namespace PKHeX.Core.Tests.Simulator; public class GeneratorTests { - public static IEnumerable PokemonGenerationTestData() + private const string SkipReasonLong = "Long duration test, run manually & very infrequently."; + static GeneratorTests() => TestUtil.InitializeLegality(); + + public static IEnumerable GetSpecies17() => GetSpecies(PersonalTable.USUM, new SimpleTrainerInfo(GameVersion.US), () => new PK7(), Array.Empty()); + public static IEnumerable GetSpeciesLGPE() => GetSpecies(PersonalTable.GG, new SimpleTrainerInfo(GameVersion.GP), () => new PB7(), new[] { GameVersion.GP, GameVersion.GE}); + public static IEnumerable GetSpeciesSWSH() => GetSpecies(PersonalTable.SWSH, new SimpleTrainerInfo(GameVersion.SW), () => new PK8(), new[] { GameVersion.SW, GameVersion.SH }); + public static IEnumerable GetSpeciesPLA() => GetSpecies(PersonalTable.LA, new SimpleTrainerInfo(GameVersion.PLA), () => new PA8(), new[] { GameVersion.PLA }); + public static IEnumerable GetSpeciesBDSP() => GetSpecies(PersonalTable.BDSP, new SimpleTrainerInfo(GameVersion.BD), () => new PB8(), new[] { GameVersion.BD, GameVersion.SP }); + public static IEnumerable GetSpeciesSV() => GetSpecies(PersonalTable.SV, new SimpleTrainerInfo(GameVersion.SL), () => new PK9(), new[] { GameVersion.SL, GameVersion.VL }); + + private static IEnumerable GetSpecies(T table, SimpleTrainerInfo tr, Func ctor, GameVersion[] games) where T : IPersonalTable { - for (int i = 1; i <= 807; i++) - yield return new object[] { i }; + for (ushort i = 1; i <= table.MaxSpeciesID; i++) + { + if (table.IsSpeciesInGame(i)) + yield return new object[] { (Species)i, tr, ctor(), games }; + } } - [Theory(Skip = "Long duration test, run manually & very infrequently.")] - [MemberData(nameof(PokemonGenerationTestData))] - public void PokemonGenerationReturnsLegalPokemon(ushort species) + [Theory(Skip = SkipReasonLong)] + [MemberData(nameof(GetSpecies17))] + [MemberData(nameof(GetSpeciesLGPE))] + [MemberData(nameof(GetSpeciesSWSH))] + [MemberData(nameof(GetSpeciesPLA))] + [MemberData(nameof(GetSpeciesBDSP))] + [MemberData(nameof(GetSpeciesSV))] + public void PokemonGenerationReturnsLegalPokemon(Species species, SimpleTrainerInfo tr, Core.PKM template, GameVersion[] games) { int count = 0; - var tr = new SimpleTrainerInfo(GameVersion.SN); - - var template = new PK7 { Species = species }; + template.Species = (ushort)species; template.Gender = template.PersonalInfo.RandomGender(); - var encounters = EncounterMovesetGenerator.GenerateEncounters(template, tr, Array.Empty()); + var encounters = EncounterMovesetGenerator.GenerateEncounters(template, tr, Array.Empty(), games); foreach (var enc in encounters) { var pk = enc.ConvertToPKM(tr); var la = new LegalityAnalysis(pk); - la.Valid.Should().BeTrue($"Because encounter #{count} for {(Species)species} ({species:000}) should be valid, {Environment.NewLine}{la.Report()}"); + la.Valid.Should().BeTrue($"Because encounter #{count} for {species} ({(ushort)species:000}) should be valid, {Environment.NewLine}{la.Report()}{Environment.NewLine}{enc}"); count++; } } diff --git a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs index ffdbb2b20..15393a2f6 100644 --- a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs +++ b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs @@ -16,4 +16,19 @@ internal static class TestUtil } return folder; } + + private static readonly object InitLock = new(); + private static bool IsInitialized; + + public static void InitializeLegality() + { + lock (InitLock) + { + if (IsInitialized) + return; + RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons); + IsInitialized = true; + } + } + }