feat(world-gen): add WormHash deterministic mixing function
This commit is contained in:
40
VoxelEngine.Tests/WorldGen/WormHashTests.cs
Normal file
40
VoxelEngine.Tests/WorldGen/WormHashTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user