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).
This commit is contained in:
Kurt 2023-09-12 18:15:44 -07:00
parent 9f340b592b
commit e735d92218
3 changed files with 43 additions and 29 deletions

View file

@ -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);
}

View file

@ -9,28 +9,44 @@ namespace PKHeX.Core.Tests.Simulator;
public class GeneratorTests
{
public static IEnumerable<object[]> PokemonGenerationTestData()
private const string SkipReasonLong = "Long duration test, run manually & very infrequently.";
static GeneratorTests() => TestUtil.InitializeLegality();
public static IEnumerable<object[]> GetSpecies17() => GetSpecies(PersonalTable.USUM, new SimpleTrainerInfo(GameVersion.US), () => new PK7(), Array.Empty<GameVersion>());
public static IEnumerable<object[]> GetSpeciesLGPE() => GetSpecies(PersonalTable.GG, new SimpleTrainerInfo(GameVersion.GP), () => new PB7(), new[] { GameVersion.GP, GameVersion.GE});
public static IEnumerable<object[]> GetSpeciesSWSH() => GetSpecies(PersonalTable.SWSH, new SimpleTrainerInfo(GameVersion.SW), () => new PK8(), new[] { GameVersion.SW, GameVersion.SH });
public static IEnumerable<object[]> GetSpeciesPLA() => GetSpecies(PersonalTable.LA, new SimpleTrainerInfo(GameVersion.PLA), () => new PA8(), new[] { GameVersion.PLA });
public static IEnumerable<object[]> GetSpeciesBDSP() => GetSpecies(PersonalTable.BDSP, new SimpleTrainerInfo(GameVersion.BD), () => new PB8(), new[] { GameVersion.BD, GameVersion.SP });
public static IEnumerable<object[]> GetSpeciesSV() => GetSpecies(PersonalTable.SV, new SimpleTrainerInfo(GameVersion.SL), () => new PK9(), new[] { GameVersion.SL, GameVersion.VL });
private static IEnumerable<object[]> GetSpecies<T>(T table, SimpleTrainerInfo tr, Func<Core.PKM> 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<ushort>());
var encounters = EncounterMovesetGenerator.GenerateEncounters(template, tr, Array.Empty<ushort>(), 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++;
}
}

View file

@ -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;
}
}
}