X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Frand%2FStabilityTest.cpp;h=4aab3eba000b55ccd2a5c89bfefc8773c8ce2d19;hb=19f61f6eb14b532e41a81ea850c36723d8bd9930;hp=928cdd6a464f428bda83d503fd3c7edf345ed09f;hpb=f9a060d3e46fbfb0daefc0623fa217a62e5c8c2b;p=blank.git diff --git a/tst/rand/StabilityTest.cpp b/tst/rand/StabilityTest.cpp index 928cdd6..4aab3eb 100644 --- a/tst/rand/StabilityTest.cpp +++ b/tst/rand/StabilityTest.cpp @@ -2,6 +2,7 @@ #include "rand/GaloisLFSR.hpp" #include "rand/SimplexNoise.hpp" +#include "rand/WorleyNoise.hpp" #include #include @@ -118,9 +119,9 @@ void StabilityTest::testRNG() { "unexpected value #18 from RNG", uint16_t(0xB000), value ); - random(value); + value = random.Next(); CPPUNIT_ASSERT_EQUAL_MESSAGE( - "unexpected value #19 from RNG", + "unexpected value #19 from RNG (using Next())", uint16_t(0x0B0B), value ); random(value); @@ -153,9 +154,9 @@ void StabilityTest::testRNG() { "unexpected value #25 from RNG", uint16_t(0x0000), value ); - random(value); + value = random.Next(); CPPUNIT_ASSERT_EQUAL_MESSAGE( - "unexpected value #26 from RNG", + "unexpected value #26 from RNG (using Next())", uint16_t(0xC970), value ); random(value); @@ -198,6 +199,36 @@ void StabilityTest::testRNG() { "RNG with seeds 0 and 1 differ", value, value1 ); + + GaloisLFSR random_bool(0); + bool value_bool; + for (int i = 0; i < (16 * 32); ++i) { + random_bool(value_bool); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected result for bool", + false, value_bool + ); + + GaloisLFSR random8(0); + uint8_t value8; + for (int i = 0; i < 31; ++i) { + random8(value8); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected result for uint8", + uint8_t(0x10), value8 + ); + + GaloisLFSR random32(0); + uint32_t value32; + for (int i = 0; i < 16; ++i) { + random32(value32); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected result for uint32", + uint32_t(0xB0000000), value32 + ); } void StabilityTest::testSimplex() { @@ -221,6 +252,27 @@ void StabilityTest::testSimplex() { Assert(noise, glm::vec3(-1.0f, -1.0f, -1.0f), 0.0f); } +void StabilityTest::testWorley() { + WorleyNoise noise(0); + + Assert(noise, glm::vec3(0.0f, 0.0f, 0.0f), -0.117765009403229f); + Assert(noise, glm::vec3(0.0f, 0.0f, 1.0f), -0.209876894950867f); + Assert(noise, glm::vec3(0.0f, 1.0f, 0.0f), -0.290086328983307f); + Assert(noise, glm::vec3(0.0f, 1.0f, 1.0f), -0.332393705844879f); + Assert(noise, glm::vec3(1.0f, 0.0f, 0.0f), -0.621925830841064f); + Assert(noise, glm::vec3(1.0f, 0.0f, 1.0f), -0.338455379009247f); + Assert(noise, glm::vec3(1.0f, 1.0f, 0.0f), -0.386664032936096f); + Assert(noise, glm::vec3(1.0f, 1.0f, 1.0f), -0.533940434455872f); + + Assert(noise, glm::vec3( 0.0f, 0.0f, -1.0f), -0.425480604171753f); + Assert(noise, glm::vec3( 0.0f, -1.0f, 0.0f), -0.189745843410492f); + Assert(noise, glm::vec3( 0.0f, -1.0f, -1.0f), -0.30408102273941f); + Assert(noise, glm::vec3(-1.0f, 0.0f, 0.0f), -0.618566155433655f); + Assert(noise, glm::vec3(-1.0f, 0.0f, -1.0f), -0.060045599937439f); + Assert(noise, glm::vec3(-1.0f, -1.0f, 0.0f), -0.366827547550201f); + Assert(noise, glm::vec3(-1.0f, -1.0f, -1.0f), -0.575981974601746f); +} + void StabilityTest::Assert( const SimplexNoise &noise, const glm::vec3 &position, @@ -234,5 +286,18 @@ void StabilityTest::Assert( ); } +void StabilityTest::Assert( + const WorleyNoise &noise, + const glm::vec3 &position, + float expected +) { + stringstream msg; + msg << "unexpected worley noise value at " << position; + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + msg.str(), + expected, noise(position), numeric_limits::epsilon() + ); +} + } }