Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
CI / Build e test (pull_request) Successful in 1m20s
CI / Immagine Docker (pull_request) Successful in 37s

Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*,
variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per
allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos:
CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in
server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly.
Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e
aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-07 11:14:54 +01:00
1 parent f6c2a17b4d
commit c1a0049bcf
300 files changed
+1602 -1045

No files matched your search

@@ -0,0 +1,98 @@
using RailEnterprise.Core.Common;
using RailEnterprise.Tests.Harness;
namespace RailEnterprise.Tests.Basics;
public static class CommonTests
{
[Test]
public static void MoneyFormatsItalian()
{
Assert.Equal("₤ 1.284.500", Money.FromLire(1_284_500).ToString());
Assert.Equal("₤ 1.284.500,25", Money.FromLire(1_284_500.25m).ToString("it2"));
Assert.Equal("₤ 3,91 mln", Money.FromLire(3_910_000).ToString("short"));
Assert.Equal("₤ 48.200", Money.FromLire(48_200).ToString("short"));
Assert.Equal("−₤ 19.700", Money.FromLire(-19_700).ToString());
Assert.Equal("₤ 0", Money.Zero.ToString());
Assert.Equal("₤ 999", Money.FromLire(999).ToString());
}
[Test]
public static void MoneyArithmeticIsExact()
{
var a = Money.FromLire(10.10m);
var b = Money.FromLire(0.20m);
Assert.Equal(1030L, (a + b).Cents);
Assert.Equal(990L, (a - b).Cents);
Assert.Equal(3030L, (a * 3).Cents);
Assert.Equal(1515L, (a * 1.5).Cents);
Assert.True(a > b);
Assert.Throws<OverflowException>(() => _ = new Money(long.MaxValue) + new Money(1));
}
[Test]
public static void XxHash64MatchesReferenceVectors()
{
Assert.Equal(0xef46db3751d8e999UL, XxHash64.Hash([]));
Assert.Equal(0xd24ec4f1a98c6e5bUL, XxHash64.Hash("a"u8));
Assert.Equal(0x44bc2cf5ad770999UL, XxHash64.Hash("abc"u8));
Assert.Equal(0x81cf4b9562ee9c31UL, XxHash64.Hash("Rail Enterprise"u8));
Assert.Equal(0x95584af7701f808dUL, XxHash64.Hash([], 12345));
var hundred = new byte[100];
for (int i = 0; i < hundred.Length; i++) hundred[i] = (byte)i;
Assert.Equal(0x6ac1e58032166597UL, XxHash64.Hash(hundred));
Assert.Equal(0x28ba1ae2de4de27UL, XxHash64.Hash(hundred, 12345));
}
[Test(Description = "DMath coincide con Math entro 1e-14 relativi su argomenti casuali")]
public static void DMathMatchesMathClosely()
{
var rng = new Rng(2024);
for (int i = 0; i < 20_000; i++)
{
double x = rng.NextDouble(-50, 50);
Check(Math.Exp(x), DMath.Exp(x), "exp", x);
double p = rng.NextDouble(1e-6, 1e6);
Check(Math.Log(p), DMath.Log(p), "log", p);
double a = rng.NextDouble(-1000, 1000);
CheckAbs(Math.Sin(a), DMath.Sin(a), "sin", a);
CheckAbs(Math.Cos(a), DMath.Cos(a), "cos", a);
double t = rng.NextDouble(-100, 100);
Check(Math.Atan(t), DMath.Atan(t), "atan", t);
double y = rng.NextDouble(-5, 5), xx = rng.NextDouble(-5, 5);
CheckAbs(Math.Atan2(y, xx), DMath.Atan2(y, xx), "atan2", y);
double b = rng.NextDouble(0.01, 300), e = rng.NextDouble(-3, 3);
Check(Math.Pow(b, e), DMath.Pow(b, e), "pow", b);
}
Assert.Equal(1.0, DMath.Exp(0));
Assert.Equal(0.0, DMath.Log(1));
Assert.Equal(8.0, DMath.Pow(2, 3));
Assert.Equal(0.125, DMath.Pow(2, -3));
Assert.True(double.IsNaN(DMath.Log(-1)));
Assert.Equal(double.PositiveInfinity, DMath.Exp(1000));
Assert.Equal(0.0, DMath.Exp(-1000));
Assert.Approx(Math.Exp(-740), DMath.Exp(-740), 1e-320);
Assert.Approx(Math.Log(5e-310), DMath.Log(5e-310), 1e-12);
}
private static void Check(double expected, double actual, string fn, double arg)
{
double tol = Math.Max(1e-300, Math.Abs(expected) * 2e-14);
Assert.Approx(expected, actual, tol, $"{fn}({arg:R})");
}
private static void CheckAbs(double expected, double actual, string fn, double arg)
{
Assert.Approx(expected, actual, 1e-13, $"{fn}({arg:R})");
}
[Test]
public static void TypedIdsAreDistinctAndOrdered()
{
var a = new StationId(3);
var b = new StationId(5);
Assert.True(a.CompareTo(b) < 0);
Assert.False(StationId.None.IsValid);
Assert.Equal("Station#3", a.ToString());
}
}
@@ -0,0 +1,66 @@
using RailEnterprise.Core.Common;
using RailEnterprise.Tests.Harness;
namespace RailEnterprise.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);
}
}
@@ -0,0 +1,46 @@
using RailEnterprise.Core.Time;
using RailEnterprise.Tests.Harness;
namespace RailEnterprise.Tests.Basics;
public static class TimeTests
{
private static Calendar Cal() => new(TestData.Data.Balance.Time, 1850);
[Test]
public static void CalendarConstantsMatchGuide()
{
var c = Cal();
Assert.Equal(240, c.TicksPerDay);
Assert.Equal(360, c.DaysPerYear);
Assert.Approx(3.0, c.TrainSecondsPerTick, 1e-12, "un tick = 3 s di orologio dei treni");
Assert.Approx(2.5, c.TrainMinutesToDays(30), 1e-12, "30 minuti di orologio = 2,5 giorni");
}
[Test]
public static void DatesRoundTripAndFormatInItalian()
{
var c = Cal();
var d = c.DateOfDay(22 * 360 + 2 * 30 + 13);
Assert.Equal(new GameDate(1872, 3, 14), d);
Assert.Equal("14 marzo 1872", d.ToString());
Assert.Equal(22L * 360 + 2 * 30 + 13, c.DayOf(d));
}
[Test]
public static void ClockFlagsFireAtBoundaries()
{
var clock = new GameClock(Cal());
Assert.True(clock.IsNewDay && clock.IsNewMonth && clock.IsNewYear);
clock.Advance();
Assert.False(clock.IsNewDay);
clock.Restore(240L * 30);
Assert.True(clock.IsNewMonth);
Assert.False(clock.IsNewQuarter);
clock.Restore(240L * 90);
Assert.True(clock.IsNewQuarter);
clock.Restore(240L * 360);
Assert.True(clock.IsNewYear);
Assert.Equal(1851, clock.Year);
}
}