diff options
Diffstat (limited to 'src/unittest')
-rw-r--r-- | src/unittest/test_noise.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/unittest/test_noise.cpp b/src/unittest/test_noise.cpp index 421f3b66e..12b155f46 100644 --- a/src/unittest/test_noise.cpp +++ b/src/unittest/test_noise.cpp @@ -30,8 +30,14 @@ public: void runTests(IGameDef *gamedef); + void testNoise2dAtOriginWithZeroSeed(); + void testNoise2dWithMaxSeed(); + void testNoise2dWithFunPrimes(); void testNoise2dPoint(); void testNoise2dBulk(); + void testNoise3dAtOriginWithZeroSeed(); + void testNoise3dWithMaxSeed(); + void testNoise3dWithFunPrimes(); void testNoise3dPoint(); void testNoise3dBulk(); void testNoiseInvalidParams(); @@ -44,8 +50,14 @@ static TestNoise g_test_instance; void TestNoise::runTests(IGameDef *gamedef) { + TEST(testNoise2dAtOriginWithZeroSeed); + TEST(testNoise2dWithMaxSeed); + TEST(testNoise2dWithFunPrimes); TEST(testNoise2dPoint); TEST(testNoise2dBulk); + TEST(testNoise3dAtOriginWithZeroSeed); + TEST(testNoise3dWithMaxSeed); + TEST(testNoise3dWithFunPrimes); TEST(testNoise3dPoint); TEST(testNoise3dBulk); TEST(testNoiseInvalidParams); @@ -53,6 +65,27 @@ void TestNoise::runTests(IGameDef *gamedef) //////////////////////////////////////////////////////////////////////////////// +void TestNoise::testNoise2dAtOriginWithZeroSeed() +{ + float actual{ noise2d(0, 0, 0) }; + constexpr float expected{ -0.281791f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + +void TestNoise::testNoise2dWithMaxSeed() +{ + float actual{ noise2d(4096, 4096, 2147483647) }; + constexpr float expected{ 0.950606f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + +void TestNoise::testNoise2dWithFunPrimes() +{ + float actual{ noise2d(-3947, -2333, 7027) }; + constexpr float expected{ -0.294907f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + void TestNoise::testNoise2dPoint() { NoiseParams np_normal(20, 40, v3f(50, 50, 50), 9, 5, 0.6, 2.0); @@ -79,6 +112,27 @@ void TestNoise::testNoise2dBulk() } } +void TestNoise::testNoise3dAtOriginWithZeroSeed() +{ + float actual{ noise2d(0, 0, 0) }; + constexpr float expected{ -0.281791f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + +void TestNoise::testNoise3dWithMaxSeed() +{ + float actual{ noise3d(4096, 4096, 4096, 2147483647) }; + constexpr float expected{ -0.775243f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + +void TestNoise::testNoise3dWithFunPrimes() +{ + float actual{ noise2d(3903, -1723, 7411) }; + constexpr float expected{ 0.989124f }; + UASSERT(std::fabs(actual - expected) <= 0.00001); +} + void TestNoise::testNoise3dPoint() { NoiseParams np_normal(20, 40, v3f(50, 50, 50), 9, 5, 0.6, 2.0); |