Implements critical capture, tweaks for integration tests.
All checks were successful
Build / Build (push) Successful in 48s

This commit is contained in:
2025-05-18 17:07:46 +02:00
parent cbd4340b13
commit 377c1a1c68
11 changed files with 158 additions and 52 deletions

View File

@@ -1,6 +1,8 @@
using System.Text.Json;
using EnumerableAsyncProcessor.Extensions;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7;
using PkmnLib.Static.Species;
using PkmnLib.Tests.Integration.Models;
@@ -10,7 +12,7 @@ public class IntegrationTestRunner
{
public static IEnumerable<Func<IntegrationTestModel>> TestCases()
{
var files = Directory.GetFiles("Integration/Tests", "*.json");
var files = Directory.GetFiles("../../../../PkmnLib.Tests/Integration/Tests", "*.json");
var serializerOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
@@ -32,7 +34,13 @@ public class IntegrationTestRunner
[Test, MethodDataSource(nameof(TestCases))]
public async Task RunIntegrationTest(IntegrationTestModel test)
{
var library = LibraryHelpers.LoadLibrary();
var library = DynamicLibraryImpl.Create([
new Gen7Plugin(new Gen7PluginConfiguration
{
DamageCalculatorHasRandomness = true,
}),
]);
await TestContext.Current!.OutputWriter.WriteLineAsync("File: " + $"file://{test.FileName}");
TestContext.Current.AddArtifact(new Artifact
{

View File

@@ -3,6 +3,7 @@ using System.Text.Json.Serialization;
using CSPath;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using TUnit.Core.Logging;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace PkmnLib.Tests.Integration.Models;
@@ -23,6 +24,7 @@ public class SetPokemonAction : IntegrationTestAction
{
var mon = battle.Parties[FromParty[0]].Party[FromParty[1]];
battle.Sides[Place[0]].SwapPokemon(Place[1], mon);
Console.WriteLine($"Set: {mon} to place {Place[0]}:{Place[1]}");
return Task.CompletedTask;
}
}
@@ -42,6 +44,8 @@ public class SetMoveChoiceAction : IntegrationTestAction
await Assert.That(move).IsNotNull();
var res = battle.TrySetChoice(new MoveChoice(user, move!, Target[0], Target[1]));
await Assert.That(res).IsTrue();
var target = battle.Sides[Target[0]].Pokemon[Target[1]];
Console.WriteLine($"Choice: {user} used {move} on {target} ({Target[0]}:{Target[1]})");
}
}
@@ -56,13 +60,14 @@ public class SetPassChoiceAction : IntegrationTestAction
await Assert.That(user).IsNotNull();
var res = battle.TrySetChoice(new PassChoice(user!));
await Assert.That(res).IsTrue();
Console.WriteLine($"Choice: {user} Pass");
}
}
public class AssertAction : IntegrationTestAction
{
public string Value { get; set; } = null!;
public JsonNode Expected { get; set; } = null!;
public string Value { get; init; } = null!;
public JsonNode Expected { get; init; } = null!;
/// <inheritdoc />
public override async Task Execute(IBattle battle)
@@ -71,6 +76,9 @@ public class AssertAction : IntegrationTestAction
var value = list.Count == 1 ? list[0] : list;
var serialized = JsonSerializer.Serialize(value);
await Assert.That(serialized).IsEqualTo(Expected.ToJsonString());
#pragma warning disable TUnitAssertions0003
await Assert.That(serialized, Value).IsEqualTo(Expected.ToJsonString());
#pragma warning restore TUnitAssertions0003
Console.WriteLine($"Assert: {Value} = {serialized}");
}
}

View File

@@ -8,22 +8,36 @@
"positionsPerSide": 1,
"parties": [
{
"indices": [[0, 0]],
"indices": [
[
0,
0
]
],
"pokemon": [
{
"species": "charizard",
"level": 50,
"moves": ["ember"]
"moves": [
"ember"
]
}
]
},
{
"indices": [[1, 0]],
"indices": [
[
1,
0
]
],
"pokemon": [
{
"species": "venusaur",
"level": 50,
"moves": ["vine_whip"]
"moves": [
"vine_whip"
]
}
]
}
@@ -32,13 +46,25 @@
"actions": [
{
"$type": "setPokemon",
"place": [0, 0],
"fromParty": [0, 0]
"place": [
0,
0
],
"fromParty": [
0,
0
]
},
{
"$type": "setPokemon",
"place": [1, 0],
"fromParty": [1, 0]
"place": [
1,
0
],
"fromParty": [
1,
0
]
},
{
"$type": "assert",
@@ -47,18 +73,27 @@
},
{
"$type": "setMoveChoice",
"place": [0, 0],
"place": [
0,
0
],
"move": "ember",
"target": [1, 0]
"target": [
1,
0
]
},
{
"$type": "setPassChoice",
"place": [1, 0]
"place": [
1,
0
]
},
{
"$type": "assert",
"value": ".Sides[1].Pokemon[0].CurrentHealth",
"expected": 78
"expected": 84
}
]
}

View File

@@ -30,16 +30,7 @@
<ProjectReference Include="..\PkmnLib.Static\PkmnLib.Static.csproj"/>
<ProjectReference Include="..\Plugins\PkmnLib.Plugin.Gen7\PkmnLib.Plugin.Gen7.csproj"/>
</ItemGroup>
<ItemGroup>
<None Update="Data\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Integration\Tests\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="WorkaroundRider117732" AfterTargets="Build" Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
<Copy Condition="Exists('$(OutputPath)$(AssemblyName)')" SourceFiles="$(OutputPath)$(AssemblyName)" DestinationFiles="$(OutputPath)$(AssemblyName).exe"/>
</Target>