diff --git a/Tests/PKHeX.Tests/Legality/Legal/General/610 - キバゴ - 6F91B110EED1.pk5 b/Tests/PKHeX.Tests/Legality/Legal/General/610 - キバゴ - 6F91B110EED1.pk5 new file mode 100644 index 000000000..1dd396a81 Binary files /dev/null and b/Tests/PKHeX.Tests/Legality/Legal/General/610 - キバゴ - 6F91B110EED1.pk5 differ diff --git a/Tests/PKHeX.Tests/Legality/LegalityTests.cs b/Tests/PKHeX.Tests/Legality/LegalityTests.cs index 32ebef53f..a9b2a8136 100644 --- a/Tests/PKHeX.Tests/Legality/LegalityTests.cs +++ b/Tests/PKHeX.Tests/Legality/LegalityTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; using PKHeX.Core; namespace PKHeX.Tests.Legality @@ -6,10 +7,11 @@ namespace PKHeX.Tests.Legality [TestClass] public class LegalityTest { - private const string LegalityTestCategory = "PKM PIDIV Matching Tests"; + private const string LegalityWordCategory = "PKM Wordfilter Tests"; + private const string LegalityValidCategory = "PKM Validity Tests"; [TestMethod] - [TestCategory(LegalityTestCategory)] + [TestCategory(LegalityWordCategory)] public void BadwordTest() { string[] phrases = @@ -19,5 +21,41 @@ namespace PKHeX.Tests.Legality foreach (var phrase in phrases) Assert.IsTrue(WordFilter.IsFiltered(phrase, out _), $"Word not filtered: {phrase}."); } + + [TestMethod] + [TestCategory(LegalityValidCategory)] + public void VerifyLegalityTest() + { + var folder = Directory.GetCurrentDirectory(); + while (!folder.EndsWith(nameof(Tests))) + folder = Directory.GetParent(folder).FullName; + + folder = Path.Combine(folder, "Legality"); + VerifyAll(folder, "Legal", true); + } + + // ReSharper disable once UnusedParameter.Local + private static void VerifyAll(string folder, string name, bool IsValid) + { + var path = Path.Combine(folder, name); + Assert.IsTrue(Directory.Exists(path), $"Folder does not exist: {folder}."); + var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories); + foreach (var file in files) + { + var fi = new FileInfo(file); + Assert.IsNotNull(fi, $"Invalid file: {file}"); + Assert.IsTrue(PKX.IsPKM(fi.Length), $"Invalid file in {fi.Directory.Name} folder."); + + var data = File.ReadAllBytes(file); + var format = file[file.Length - 1] - '0'; + if (format > 10) + format = 6; + var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format); + Assert.IsNotNull(pkm, $"Failed to load PKM: {new FileInfo(file).Name}."); + + var legality = new LegalityAnalysis(pkm); + Assert.IsTrue(legality.Valid == IsValid, $"Failed to validate PKM as {(IsValid ? "Valid" : "Invalid")}: {fi.Directory.Name}\\{fi.Name}."); + } + } } }