Files
Rail_Enterprise/tests/ViaFerrea.Tests/Core/RngTests.cs
T
Claude 7cb98fa206 F1: economia headless, dati validati, generatore di mappa e salvataggi
- Base deterministica: Money, id tipizzati, DMath, XxHash64, calendario
- 12 file dati con schemi, validatore di schema interno, validazione semantica
  e hash dei dati; viaferrea-tools validate-data
- Generatore di mappa (rilievo, mare, priority-flood, fiumi, laghi, copertura,
  giacimenti, città, hub, industrie) e viaferrea-tools genmap
- Economia: città, industrie, hub, mercato con componente mondiale, prezzi
  locali, tariffe, lavoro in sede e a piedi, trasporto locale, registro a
  partita doppia, prestiti, rating, difficoltà
- Salvataggi Brotli con rimappatura per id e hash di stato giornaliero
- viaferrea-tools simulate con KPI CSV; 45 test verdi; ADR 0002-0006

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
2026-10-01 22:38:17 +00:00

67 lines
1.9 KiB
C#

using ViaFerrea.Core.Common;
using ViaFerrea.Tests.Harness;
namespace ViaFerrea.Tests.Basics;
public static class RngTests
{
[Test(Description = "Vettore di riferimento di xoshiro256** con stato {1,2,3,4}")]
public static void Xoshiro256StarStarMatchesReferenceVector()
{
var rng = Rng.FromState(1, 2, 3, 4);
Assert.Equal(11520UL, rng.NextU64());
Assert.Equal(0UL, rng.NextU64());
Assert.Equal(1509978240UL, rng.NextU64());
Assert.Equal(1215971899390074240UL, rng.NextU64());
}
[Test]
public static void SameSeedGivesSameSequence()
{
var a = new Rng(42);
var b = new Rng(42);
for (int i = 0; i < 1000; i++) Assert.Equal(a.NextU64(), b.NextU64());
}
[Test]
public static void ForkIsStableAndDoesNotConsumeParent()
{
var root = new Rng(7);
var before = root.State;
var f1 = root.Fork("industries");
var f2 = root.Fork("industries");
var f3 = root.Fork("towns");
Assert.Equal(before, root.State);
Assert.Equal(f1.NextU64(), f2.NextU64());
Assert.NotEqual(new Rng(7).Fork("industries").NextU64(), f3.NextU64());
}
[Test]
public static void NextIntIsInRangeAndRoughlyUniform()
{
var rng = new Rng(123);
var counts = new int[10];
for (int i = 0; i < 100_000; i++)
{
int v = rng.NextInt(10);
Assert.True(v is >= 0 and < 10);
counts[v]++;
}
foreach (int c in counts) Assert.InRange(c, 9_500, 10_500);
}
[Test]
public static void NextDoubleIsInUnitInterval()
{
var rng = new Rng(99);
double sum = 0;
for (int i = 0; i < 100_000; i++)
{
double d = rng.NextDouble();
Assert.True(d >= 0 && d < 1);
sum += d;
}
Assert.Approx(0.5, sum / 100_000, 0.01);
}
}