F0: fondamenta della soluzione, script, documenti e harness di test
- ViaFerrea.sln con Core e Protocol (net10.0 + net8.0), Server, Tools, Tests - Directory.Build.props con versione unica e warning come errori - Script build/test/check-nuget/publish-image (+ build.ps1) - Documenti: GUIDA, GDD, ARCHITECTURE, PROTOCOL (bozza), STATE, ADR 0001 - Harness di test interno con i primi test su Rng (xoshiro256**) - Immagini di riferimento 01-05 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
36 files changed
+1647
-2
No files matched your search
@@ -0,0 +1,66 @@
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Tests.Harness;
|
||||
|
||||
namespace ViaFerrea.Tests.Core;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user