champions-of-luneraria/tools/dotnet/Luneraria.Core.Tests/Program.cs
Martin Stickelbroeck 4d6ed17dca U1: Regelkern in C#, verhaltensgleich zur Godot-Referenz
Vollständiger, engineunabhängiger Regelkern (Luneraria.Core, ohne
UnityEngine): Partie mit sechs Plätzen und zwei Teams, private Planung mit
atomarer Übernahme, Gold, Käufe, Aufwertungen, Formation, drei Lanes mit
zwei Laneturmen und zwei Basistürmen je Team, Ancients, unbegrenzte Wellen,
Helden mit Stufen, Items und Talenten, Angriffschampions, Bossgrotte mit
Anspruch, Entsendung, Kopfgeld und dreirundiger Sperre, Bots und
Siegbedingung (nur Ancient-Fall). Serverautoritative Befehlsschnittstelle.

- Deterministisch: fester Takt, geordnete Maps, fortlaufende IDs, kein
  Zufall, keine Uhr, keine Threads
- Tabellen einmal aus Godot erzeugt (tools/port/gen_content.py)
- Golden-Referenzen aus Godot (tools/godot-golden): 19 Szenarien,
  120 Snapshots, 51.221 Werte, Abweichung 0 (Toleranzen dokumentiert)
- Tests: content 75, core 91, m2 73, golden 157, determinism 6 = 402/402
- Leistung (M5): Simulationsschritt 0,259 ms statt 1,587 ms in GDScript
- Referenzfehler R1 im Bot-Gedächtnis bewusst übernommen und dokumentiert
- Geplante Helden (Lucy, Ghaliga, Siegfried, Feena) im Datenmodell, inaktiv
- Doku unter docs/port (U1-RULES, PORT-STATUS, PORT-QA, U2 bis U5)

Unity-Editor-Lauf offen: Die Unity-Lizenz ist noch nicht aktiviert; gebaut
und getestet mit dem .NET 8 SDK auf Unitys Sprachstand (C# 9, .NET
Standard 2.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 14:31:18 +02:00

72 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Luneraria.Core.Tests
{
/// <summary>
/// Console runner: dotnet run --project tools/dotnet/Luneraria.Core.Tests -- [suite ...]
/// Writes docs/port/logs/u1/core-tests.json and exits non-zero on any failure.
/// </summary>
public static class Program
{
public static int Main(string[] args)
{
string root = FindRoot();
string golden = Path.Combine(root, "Assets/Luneraria/Tests/Core/Golden");
if (args.Length == 4 && args[0] == "--image")
return ReplayImage.Write(golden, args[1], args[2], Path.GetFullPath(args[3]));
var wanted = new HashSet<string>(args);
var report = new StringBuilder("{\n \"suites\": [\n");
int failures = 0;
bool first = true;
foreach (CheckSuite suite in CheckSuite.All())
{
if (wanted.Count > 0 && !wanted.Contains(suite.Name))
continue;
suite.GoldenDirectory = golden;
var clock = Stopwatch.StartNew();
bool ok = suite.Run();
clock.Stop();
failures += suite.Failures.Count;
Console.WriteLine("LUNE_U1_{0} {1}: {2} checks; {3} failures ({4:0.0} s)", ok ? "PASS" : "FAIL", suite.Name, suite.Checks, suite.Failures.Count, clock.Elapsed.TotalSeconds);
foreach (string failure in suite.Failures)
Console.WriteLine(" FAIL " + failure);
foreach (string note in suite.Notes)
Console.WriteLine(" note " + note);
report.Append(first ? "" : ",\n");
first = false;
report.AppendFormat(" {{\"suite\": \"{0}\", \"checks\": {1}, \"failures\": {2}, \"seconds\": {3:0.00}, \"failed\": [{4}], \"notes\": [{5}]}}",
suite.Name, suite.Checks, suite.Failures.Count, clock.Elapsed.TotalSeconds, Join(suite.Failures), Join(suite.Notes));
}
report.Append("\n ],\n \"runtime\": \"" + System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription + "\",\n");
report.Append(" \"os\": \"" + System.Runtime.InteropServices.RuntimeInformation.OSDescription + " " + System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture + "\"\n}\n");
if (wanted.Count == 0)
{
string logs = Path.Combine(root, "docs/port/logs/u1");
Directory.CreateDirectory(logs);
File.WriteAllText(Path.Combine(logs, "core-tests.json"), report.ToString());
}
Console.WriteLine(failures == 0 ? "LUNE_U1_TESTS_OK" : "LUNE_U1_TESTS_FAILED");
return failures == 0 ? 0 : 1;
}
static string Join(List<string> values)
{
var parts = new List<string>();
foreach (string value in values)
parts.Add("\"" + value.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\n") + "\"");
return string.Join(", ", parts);
}
static string FindRoot()
{
string dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Assets/Luneraria")))
dir = Path.GetDirectoryName(dir);
return dir ?? Directory.GetCurrentDirectory();
}
}
}