mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-15 08:47:14 +00:00
Add legality test case setup
hopefully the pathfinding isn't machine sensistive...
This commit is contained in:
parent
d56354822c
commit
1ea29eb66c
2 changed files with 40 additions and 2 deletions
Binary file not shown.
|
@ -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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue