From 1656f437474bc5bfdc626a7d566880f3949cab55 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Thu, 27 Aug 2026 09:55:36 +0200 Subject: [PATCH] test: add tests for terrain shaping parameters --- tests/testTerrain.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/testTerrain.cpp diff --git a/tests/testTerrain.cpp b/tests/testTerrain.cpp new file mode 100644 index 0000000..9ca358a --- /dev/null +++ b/tests/testTerrain.cpp @@ -0,0 +1,90 @@ +#include "testHarness.h" +#include "vf/Terrain.h" + +using namespace vf; + +namespace { + +int topSolid(const World& world, int gx, int gz, int worldHeight) { + for (int y = worldHeight - 1; y >= 0; --y) + if (world.solidAt(gx, y, gz)) return y; + return -1; +} + +} // namespace + +VF_TEST(terrainIsDeterministicForSeed) { + TerrainParams params; + params.chunksX = 2; + params.chunksZ = 2; + params.worldHeight = 48; + World a, b; + generateTerrain(a, params); + generateTerrain(b, params); + + for (int x = 0; x < 2 * chunkSize; ++x) + for (int y = 0; y < params.worldHeight; ++y) + for (int z = 0; z < 2 * chunkSize; ++z) + CHECK(a.blockAt(x, y, z) == b.blockAt(x, y, z)); +} + +VF_TEST(terrainDiffersBetweenSeeds) { + TerrainParams p1; + p1.chunksX = 2; + p1.chunksZ = 2; + p1.worldHeight = 48; + TerrainParams p2 = p1; + p2.seed = 9001u; + + World a, b; + generateTerrain(a, p1); + generateTerrain(b, p2); + + bool anyDifference = false; + for (int x = 0; x < 2 * chunkSize && !anyDifference; ++x) + for (int z = 0; z < 2 * chunkSize && !anyDifference; ++z) + if (topSolid(a, x, z, p1.worldHeight) != topSolid(b, x, z, p2.worldHeight)) + anyDifference = true; + CHECK(anyDifference); +} + +VF_TEST(terrainHeightMatchesColumnHelperAndIsBounded) { + TerrainParams params; + params.chunksX = 2; + params.chunksZ = 2; + params.worldHeight = 48; + World world; + generateTerrain(world, params); + + int minH = params.worldHeight; + int maxH = 0; + for (int x = 0; x < 2 * chunkSize; ++x) { + for (int z = 0; z < 2 * chunkSize; ++z) { + int top = topSolid(world, x, z, params.worldHeight); + int expected = columnHeight(params.seed, params, x, z); + CHECK_EQ(top, expected); + CHECK(top >= 1 && top < params.worldHeight); + if (top < minH) minH = top; + if (top > maxH) maxH = top; + } + } + CHECK(minH < maxH); // terrain is not flat +} + +VF_TEST(terrainColumnAboveSurfaceIsNotStoneCore) { + TerrainParams params; + params.chunksX = 1; + params.chunksZ = 1; + params.worldHeight = 48; + World world; + generateTerrain(world, params); + + for (int x = 0; x < chunkSize; ++x) { + for (int z = 0; z < chunkSize; ++z) { + int top = topSolid(world, x, z, params.worldHeight); + Block below = world.blockAt(x, 0, z); + CHECK(below == Block::Stone); // bedrock-ish base is always stone + CHECK(world.solidAt(x, top, z)); + } + } +}