55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.IO;
|
|
using Backend;
|
|
using Xunit;
|
|
|
|
namespace Backend.Tests;
|
|
|
|
public class GameProcessTests
|
|
{
|
|
private static string LocateCliBinary()
|
|
{
|
|
var dir = AppContext.BaseDirectory;
|
|
while (dir is not null)
|
|
{
|
|
var candidate = Path.Combine(dir, "publish", "GameCli", "GameCli");
|
|
if (File.Exists(candidate)) return candidate;
|
|
var parent = Directory.GetParent(dir);
|
|
if (parent is null) break;
|
|
dir = parent.FullName;
|
|
}
|
|
throw new FileNotFoundException(
|
|
"publish/GameCli/GameCli not found — run `dotnet publish GameCli -c Release -o publish/GameCli`");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StartsAndReadsInitHandshake()
|
|
{
|
|
await using var proc = new GameProcess(LocateCliBinary());
|
|
await proc.StartAsync();
|
|
Assert.Equal(0.02f, proc.Dt);
|
|
Assert.Equal(7, proc.ObsDim);
|
|
Assert.Equal(4, proc.NActions);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StepReturnsSevenDimObservation()
|
|
{
|
|
await using var proc = new GameProcess(LocateCliBinary());
|
|
await proc.StartAsync();
|
|
var obs = await proc.StepAsync(action: 0, target: (0.5f, 0.5f));
|
|
Assert.Equal(7, obs.Observation.Length);
|
|
Assert.Equal(1, obs.Step);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ResetClearsStepCounter()
|
|
{
|
|
await using var proc = new GameProcess(LocateCliBinary());
|
|
await proc.StartAsync();
|
|
for (int i = 0; i < 3; i++)
|
|
await proc.StepAsync(action: 0, target: (0.5f, 0.5f));
|
|
var afterReset = await proc.ResetAsync(seed: 42);
|
|
Assert.Equal(0, afterReset.Step);
|
|
}
|
|
}
|