54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
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);
|
|
var noise = new NoiseSource(seed);
|
|
var cells = new VoronoiCells(seed, 96f);
|
|
var map = new BiomeMap(noise, cells, biomes);
|
|
return new TerrainSampler(noise, map);
|
|
}
|
|
|
|
[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 (those would be 25+ blocks).
|
|
// Remaining deltas are rugged intra-Mountains ridged slopes (~9), which
|
|
// are intended terrain, not cliffs; 16 separates the two.
|
|
int dx = System.Math.Abs(sampler.HeightAt(x, z) - sampler.HeightAt(x + 1, z));
|
|
Assert.True(dx <= 16, $"height jump {dx} at ({x},{z})");
|
|
}
|
|
}
|
|
}
|