101 lines
3.9 KiB
C#
101 lines
3.9 KiB
C#
|
using System.Collections;
|
||
|
using System.Text.Json;
|
||
|
using PkmnLib.Dataloader;
|
||
|
using PkmnLib.Dynamic.Libraries;
|
||
|
using PkmnLib.Dynamic.Models;
|
||
|
using PkmnLib.Plugin.Gen7;
|
||
|
using PkmnLib.Static.Libraries;
|
||
|
using PkmnLib.Static.Species;
|
||
|
using PkmnLib.Tests.Integration.Models;
|
||
|
|
||
|
namespace PkmnLib.Tests.Integration;
|
||
|
|
||
|
public class IntegrationTestRunner
|
||
|
{
|
||
|
private static IEnumerable TestCases
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
var files = Directory.GetFiles("Integration/Tests", "*.json");
|
||
|
var serializerOptions = new JsonSerializerOptions
|
||
|
{
|
||
|
PropertyNameCaseInsensitive = true,
|
||
|
};
|
||
|
foreach (var file in files)
|
||
|
{
|
||
|
var json = File.ReadAllText(file);
|
||
|
var test = JsonSerializer.Deserialize<IntegrationTestModel>(json, serializerOptions)!;
|
||
|
yield return new TestCaseData(test).SetName(test.Name).SetDescription(test.Description);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static IDynamicLibrary LoadLibrary()
|
||
|
{
|
||
|
using var typesFile = File.Open("Data/Types.csv", FileMode.Open);
|
||
|
var types = TypeDataLoader.LoadTypeLibrary(typesFile);
|
||
|
using var naturesFile = File.Open("Data/Natures.csv", FileMode.Open);
|
||
|
var natures = NatureDataLoader.LoadNatureLibrary(naturesFile);
|
||
|
using var movesFile = File.Open("Data/Moves.json", FileMode.Open);
|
||
|
var moves = MoveDataLoader.LoadMoves(movesFile, types);
|
||
|
using var itemsFile = File.Open("Data/Items.json", FileMode.Open);
|
||
|
var items = ItemDataLoader.LoadItems(itemsFile);
|
||
|
using var abilitiesFile = File.Open("Data/Abilities.json", FileMode.Open);
|
||
|
var abilities = AbilityDataLoader.LoadAbilities(abilitiesFile);
|
||
|
using var growthRatesFile = File.Open("Data/GrowthRates.json", FileMode.Open);
|
||
|
var growthRates = GrowthRateDataLoader.LoadGrowthRates(growthRatesFile);
|
||
|
using var speciesFile = File.Open("Data/Pokemon.json", FileMode.Open);
|
||
|
var species = SpeciesDataLoader.LoadSpecies(speciesFile, types);
|
||
|
|
||
|
var staticLibrary = new StaticLibraryImpl(new LibrarySettings()
|
||
|
{
|
||
|
MaxLevel = 100,
|
||
|
ShinyRate = 4096,
|
||
|
}, species, moves, abilities, types, natures, growthRates, items);
|
||
|
|
||
|
var dynamicLibrary = DynamicLibraryImpl.Create(staticLibrary, [
|
||
|
new Gen7Plugin(new Gen7PluginConfiguration()
|
||
|
{
|
||
|
DamageCalculatorHasRandomness = false,
|
||
|
}),
|
||
|
]);
|
||
|
return dynamicLibrary;
|
||
|
}
|
||
|
|
||
|
[TestCaseSource(nameof(TestCases))]
|
||
|
public void RunIntegrationTest(IntegrationTestModel test)
|
||
|
{
|
||
|
var library = LoadLibrary();
|
||
|
|
||
|
var parties = test.BattleSetup.Parties.Select(IBattleParty (x) =>
|
||
|
{
|
||
|
var party = new PokemonParty(6);
|
||
|
for (var index = 0; index < x.Pokemon.Length; index++)
|
||
|
{
|
||
|
var pokemon = x.Pokemon[index];
|
||
|
Assert.That(library.StaticLibrary.Species.TryGet(pokemon.Species, out var species), Is.True);
|
||
|
var mon = new PokemonImpl(library, species!, species!.GetDefaultForm(), new AbilityIndex
|
||
|
{
|
||
|
IsHidden = false,
|
||
|
Index = 0,
|
||
|
},
|
||
|
pokemon.Level, 0, Gender.Genderless, 0, "hardy");
|
||
|
foreach (var move in pokemon.Moves)
|
||
|
{
|
||
|
mon.LearnMove(move, MoveLearnMethod.Unknown, 255);
|
||
|
}
|
||
|
|
||
|
party.SwapInto(mon, index);
|
||
|
}
|
||
|
|
||
|
return new BattlePartyImpl(party, x.Indices.Select(y => new ResponsibleIndex(y[0], y[1])).ToArray());
|
||
|
}).ToArray();
|
||
|
var battle = new BattleImpl(library, parties, test.BattleSetup.CanFlee, test.BattleSetup.NumberOfSides,
|
||
|
test.BattleSetup.PositionsPerSide);
|
||
|
|
||
|
foreach (var action in test.Actions)
|
||
|
{
|
||
|
action.Execute(battle);
|
||
|
}
|
||
|
}
|
||
|
}
|