using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Luneraria.Core.Tests
{
///
/// Golden replays: every scenario of Golden/scenarios.json runs on the C# core and each
/// snapshot is compared with the Godot reference (Golden/golden.json) field by field.
/// Integers, strings, flags, ids, ownership, purchases, targets and results must be equal;
/// numbers that pass through floating point use the tolerances below (docs/port/U1-RULES.md).
/// The largest deviation per category is noted in the report.
///
public sealed partial class GoldenSuite
{
/// Tolerance categories: hit points (absolute, 0.01 HP or 1e-9 relative), positions and lane progress (1 mm), angles, times, effects.
static readonly Dictionary Tolerances = new Dictionary
{
{ "hp", 0.01 }, { "position", 0.001 }, { "angle", 0.0001 }, { "time", 0.000001 }, { "effect", 0.000001 }, { "other", 0.000001 },
};
readonly Dictionary _worst = new Dictionary();
readonly Dictionary _counts = new Dictionary();
int _compared;
partial void RunScenarios()
{
var spec = MiniJson.Obj(MiniJson.Parse(File.ReadAllText(Path.Combine(GoldenDirectory, "scenarios.json"))));
var golden = MiniJson.Obj(MiniJson.Obj(MiniJson.Parse(File.ReadAllText(Path.Combine(GoldenDirectory, "golden.json"))))["scenarios"]);
foreach (object item in MiniJson.Arr(spec["scenarios"]))
{
var scenario = MiniJson.Obj(item);
string id = MiniJson.Str(scenario["id"]);
object reference;
if (!golden.TryGetValue(id, out reference))
{
Check(false, id + ": no golden reference (run tools/godot-golden/run_golden.sh)");
continue;
}
var replay = new GoldenReplay();
foreach (object op in MiniJson.Arr(scenario["ops"]))
replay.Apply(MiniJson.Obj(op));
var expected = MiniJson.Obj(reference);
List