Files
Christopher Wiebe b451f83174 Initial commit: Theriapolis baseline at port/godot branch point
Captures the pre-Godot-port state of the codebase. This is the rollback
anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md).
All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 20:40:51 -07:00

78 lines
2.2 KiB
C#

using Theriapolis.Core.Util;
using Xunit;
namespace Theriapolis.Tests.Determinism;
/// <summary>
/// Phase 0 smoke tests: two SeededRng instances with the same seed must produce
/// identical outputs, and different seeds must diverge.
/// </summary>
public sealed class SeededRngTests
{
[Fact]
public void SameSeed_ProducesSameSequence()
{
var a = new SeededRng(123);
var b = new SeededRng(123);
for (int i = 0; i < 1000; i++)
Assert.Equal(a.NextUInt64(), b.NextUInt64());
}
[Fact]
public void DifferentSeeds_ProduceDifferentSequences()
{
var a = new SeededRng(123);
var b = new SeededRng(456);
bool anyDifferent = false;
for (int i = 0; i < 10; i++)
if (a.NextUInt64() != b.NextUInt64()) { anyDifferent = true; break; }
Assert.True(anyDifferent, "Different seeds should produce different sequences.");
}
[Fact]
public void ZeroSeed_DoesNotGetStuck()
{
var rng = new SeededRng(0);
ulong prev = rng.NextUInt64();
bool moved = false;
for (int i = 0; i < 5; i++)
{
ulong next = rng.NextUInt64();
if (next != prev) { moved = true; break; }
prev = next;
}
Assert.True(moved, "RNG must advance even from seed 0.");
}
[Fact]
public void NextFloat_InRange()
{
var rng = new SeededRng(999);
for (int i = 0; i < 10_000; i++)
{
float f = rng.NextFloat();
Assert.True(f >= 0f && f < 1f, $"float {f} out of [0,1)");
}
}
[Fact]
public void ForSubsystem_DifferentTagsProduceDifferentStreams()
{
var a = SeededRng.ForSubsystem(0xDEADBEEF, Theriapolis.Core.C.RNG_TERRAIN);
var b = SeededRng.ForSubsystem(0xDEADBEEF, Theriapolis.Core.C.RNG_MOISTURE);
Assert.NotEqual(a.NextUInt64(), b.NextUInt64());
}
[Fact]
public void Seed123_FirstValue_IsReproducible()
{
// Two independent instances must produce the exact same first value.
var x = new SeededRng(123).NextUInt64();
var y = new SeededRng(123).NextUInt64();
Assert.Equal(x, y);
}
}