PKHeX/Tests/PKHeX.Tests/Legality/LegalityTests.cs
Kurt e8c4cc8fa8 Fix broken crystal origin pkm test
works fine on a crystal save, the test needs this enabled for crystal
origins
2017-12-17 19:42:31 -08:00

63 lines
2.4 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using PKHeX.Core;
namespace PKHeX.Tests.Legality
{
[TestClass]
public class LegalityTest
{
private const string LegalityWordCategory = "PKM Wordfilter Tests";
private const string LegalityValidCategory = "PKM Validity Tests";
[TestMethod]
[TestCategory(LegalityWordCategory)]
public void BadwordTest()
{
string[] phrases =
{
"censor", "buttnugget", "18넘"
};
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");
Legal.AllowGBCartEra = true;
VerifyAll(folder, "Legal", true);
VerifyAll(folder, "Illegal", false);
}
// 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}.");
}
}
}
}