feat(world-gen): add WormHash deterministic mixing function

This commit is contained in:
2026-06-01 15:20:09 +02:00
parent 4587f81071
commit 013d524544
3 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using VoxelEngine.World.WorldGen;
using Xunit;
namespace VoxelEngine.Tests.WorldGen;
public class WormHashTests
{
[Fact]
public void Hash_IsDeterministic_ForSameInputs()
{
uint a = WormHash.Hash(3, -2, 7, seed: 1337);
uint b = WormHash.Hash(3, -2, 7, seed: 1337);
Assert.Equal(a, b);
}
[Fact]
public void Hash_DiffersForDifferentCells()
{
uint a = WormHash.Hash(3, -2, 7, seed: 1337);
uint b = WormHash.Hash(3, -2, 8, seed: 1337);
Assert.NotEqual(a, b);
}
[Fact]
public void Hash_DiffersForDifferentSeeds()
{
uint a = WormHash.Hash(3, -2, 7, seed: 1337);
uint b = WormHash.Hash(3, -2, 7, seed: 9999);
Assert.NotEqual(a, b);
}
[Fact]
public void Hash_HandlesNegativeCoords()
{
// Just shouldn't throw and shouldn't collide trivially with the positive case.
uint a = WormHash.Hash(-1, -1, -1, seed: 1);
uint b = WormHash.Hash(1, 1, 1, seed: 1);
Assert.NotEqual(a, b);
}
}