Preserve lazy feature placement RNG

This commit is contained in:
Daniar Mannanov 2026-08-17 18:29:10 +03:00
parent aeb7e4d2c2
commit 798016b055
4 changed files with 98 additions and 13 deletions

View file

@ -80,3 +80,43 @@ func TestLegacySetSeedResetsGaussianCache(t *testing.T) {
t.Fatalf("NextGaussian after SetSeed = %v, want %v", got, first)
}
}
func TestDecorationAndFeatureSeedVectors(t *testing.T) {
tests := []struct {
seed int64
blockX, blockZ, feature, step int
decoration int64
int16, int65 int32
floatValue float32
doubleValue float64
long int64
}{
{12345, 0, 0, 10, 6, 12345, 1, 23, 0.659135699, 0.60100983666890360, 8913713877150976631},
{12345, 16, -48, 10, 6, 95234183275347033, 12, 35, 0.821727931, 0.14700435702589810, -8289173915194761532},
{12345, -272, 672, 25, 6, -8094914473946183255, 13, 24, 0.743742824, 0.35161152187643063, 6657627925144652261},
{-987654321, 48, 80, 3, 4, 7522931011426891727, 14, 63, 0.750663280, 0.34934808320731514, -8531709575983379994},
}
for _, test := range tests {
random := NewLegacy(0)
if got := random.SetDecorationSeed(test.seed, test.blockX, test.blockZ); got != test.decoration {
t.Errorf("seed %d block (%d,%d): decoration seed = %d, want %d", test.seed, test.blockX, test.blockZ, got, test.decoration)
continue
}
random.SetFeatureSeed(test.decoration, test.feature, test.step)
if got := random.NextIntN(16); got != test.int16 {
t.Errorf("seed %d block (%d,%d): nextInt(16) = %d, want %d", test.seed, test.blockX, test.blockZ, got, test.int16)
}
if got := random.NextIntN(65); got != test.int65 {
t.Errorf("seed %d block (%d,%d): nextInt(65) = %d, want %d", test.seed, test.blockX, test.blockZ, got, test.int65)
}
if got := random.NextFloat(); math.Abs(float64(got-test.floatValue)) > 1e-7 {
t.Errorf("seed %d block (%d,%d): nextFloat = %.9f, want %.9f", test.seed, test.blockX, test.blockZ, got, test.floatValue)
}
if got := random.NextDouble(); math.Abs(got-test.doubleValue) > 1e-15 {
t.Errorf("seed %d block (%d,%d): nextDouble = %.17f, want %.17f", test.seed, test.blockX, test.blockZ, got, test.doubleValue)
}
if got := random.NextLong(); got != test.long {
t.Errorf("seed %d block (%d,%d): nextLong = %d, want %d", test.seed, test.blockX, test.blockZ, got, test.long)
}
}
}