using VoxelEngine.Core; using VoxelEngine.World.Blocks; using VoxelEngine.World.WorldGen; using Xunit; namespace VoxelEngine.Tests.WorldGen; public class TerrainSamplerTests { private static TerrainSampler Build(int seed = 42) { var blocks = new BlockRegistry(); var biomes = new BiomeRegistry(seed, blocks, new Configuration()); var noise = new NoiseSource(seed, new Configuration()); var cells = new VoronoiCells(seed, 96f); var map = new BiomeMap(noise, cells, biomes, new Configuration()); return new TerrainSampler(noise, map, new Configuration()); } [Fact] public void Height_StaysWithinWorldBounds() { var sampler = Build(); for (int x = -300; x < 300; x += 7) for (int z = -300; z < 300; z += 7) { int h = sampler.HeightAt(x, z); Assert.InRange(h, 0, WorldConstants.WorldHeight - 1); } } [Fact] public void Height_IsDeterministic() { var a = Build(); var b = Build(); Assert.Equal(a.HeightAt(120, 240), b.HeightAt(120, 240)); } [Fact] public void AdjacentColumns_DoNotCliff() { var sampler = Build(); for (int x = -200; x < 200; x += 3) for (int z = -200; z < 200; z += 3) { // The dense blur removes inter-biome cliffs. Remaining deltas are // rugged intra-Mountains ridged slopes, now ~4x larger after the // 128->512 rescale; 64 separates intended slopes from true cliffs. int dx = System.Math.Abs(sampler.HeightAt(x, z) - sampler.HeightAt(x + 1, z)); Assert.True(dx <= 64, $"height jump {dx} at ({x},{z})"); } } }