Files
TheriapolisV3/Theriapolis.Tests/Worldgen/MacroConstraintTests.cs
T
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

108 lines
3.6 KiB
C#

using Theriapolis.Core;
using Theriapolis.Core.World;
using Theriapolis.Core.World.Generation;
using Xunit;
namespace Theriapolis.Tests.Worldgen;
/// <summary>
/// Macro-template elevation and moisture constraints must hold after generation.
/// Tests from the Phase 1 acceptance criteria.
/// </summary>
public sealed class MacroConstraintTests : IClassFixture<WorldCache>
{
private const ulong TestSeed = 0xCAFEBABEUL;
private readonly WorldCache _cache;
public MacroConstraintTests(WorldCache cache) => _cache = cache;
[Fact]
public void Mountain_Cells_HaveElevation_AboveFloor()
{
var ctx = _cache.Get(TestSeed);
int W = C.WORLD_WIDTH_TILES, H = C.WORLD_HEIGHT_TILES;
int violations = 0;
for (int ty = 0; ty < H; ty += 4)
for (int tx = 0; tx < W; tx += 4)
{
ref var tile = ref ctx.World.TileAt(tx, ty);
var cell = ctx.World.MacroCellForTile(tile);
// Skip ocean tiles — they're forced below sea level regardless of macro constraint
if (tile.Biome == BiomeId.Ocean) continue;
if (cell.BiomeType.Contains("mountain", StringComparison.OrdinalIgnoreCase))
{
if (tile.Elevation < cell.ElevationFloor - 0.05f) // 5% tolerance for blending
violations++;
}
}
Assert.Equal(0, violations);
}
[Fact]
public void Grassland_Cells_HaveElevation_BelowCeiling()
{
var ctx = _cache.Get(TestSeed);
int W = C.WORLD_WIDTH_TILES, H = C.WORLD_HEIGHT_TILES;
int violations = 0;
for (int ty = 0; ty < H; ty += 4)
for (int tx = 0; tx < W; tx += 4)
{
ref var tile = ref ctx.World.TileAt(tx, ty);
if (tile.Biome == BiomeId.Ocean) continue;
var cell = ctx.World.MacroCellForTile(tile);
if (cell.BiomeType.Contains("grassland", StringComparison.OrdinalIgnoreCase))
{
if (tile.Elevation > cell.ElevationCeiling + 0.05f)
violations++;
}
}
Assert.Equal(0, violations);
}
[Fact]
public void Tundra_Cells_HaveMoisture_BelowCeiling()
{
var ctx = _cache.Get(TestSeed);
int W = C.WORLD_WIDTH_TILES, H = C.WORLD_HEIGHT_TILES;
int violations = 0;
for (int ty = 0; ty < H; ty += 4)
for (int tx = 0; tx < W; tx += 4)
{
ref var tile = ref ctx.World.TileAt(tx, ty);
if (tile.Biome == BiomeId.Ocean) continue;
var cell = ctx.World.MacroCellForTile(tile);
if (cell.BiomeType.Contains("tundra", StringComparison.OrdinalIgnoreCase))
{
if (tile.Moisture > cell.MoistureCeiling + 0.05f)
violations++;
}
}
Assert.Equal(0, violations);
}
[Fact]
public void Subtropical_Cells_HaveMoisture_AboveFloor()
{
var ctx = _cache.Get(TestSeed);
int W = C.WORLD_WIDTH_TILES, H = C.WORLD_HEIGHT_TILES;
int violations = 0;
for (int ty = 0; ty < H; ty += 4)
for (int tx = 0; tx < W; tx += 4)
{
ref var tile = ref ctx.World.TileAt(tx, ty);
if (tile.Biome == BiomeId.Ocean) continue;
var cell = ctx.World.MacroCellForTile(tile);
if (cell.BiomeType.Contains("subtropical", StringComparison.OrdinalIgnoreCase))
{
if (tile.Moisture < cell.MoistureFloor - 0.05f)
violations++;
}
}
Assert.Equal(0, violations);
}
}