1 #include "StabilityTest.hpp"
3 #include "rand/GaloisLFSR.hpp"
4 #include "rand/SimplexNoise.hpp"
9 #include <glm/gtx/io.hpp>
11 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::StabilityTest);
19 void StabilityTest::setUp() {
23 void StabilityTest::tearDown() {
28 void StabilityTest::testRNG() {
32 CPPUNIT_ASSERT_EQUAL_MESSAGE(
33 "unexpected value #1 from RNG",
34 uint16_t(0x0000), value
37 CPPUNIT_ASSERT_EQUAL_MESSAGE(
38 "unexpected value #2 from RNG",
39 uint16_t(0x0000), value
42 CPPUNIT_ASSERT_EQUAL_MESSAGE(
43 "unexpected value #3 from RNG",
44 uint16_t(0xB000), value
47 CPPUNIT_ASSERT_EQUAL_MESSAGE(
48 "unexpected value #4 from RNG",
49 uint16_t(0x0000), value
52 CPPUNIT_ASSERT_EQUAL_MESSAGE(
53 "unexpected value #5 from RNG",
54 uint16_t(0x0000), value
57 CPPUNIT_ASSERT_EQUAL_MESSAGE(
58 "unexpected value #6 from RNG",
59 uint16_t(0x0000), value
62 CPPUNIT_ASSERT_EQUAL_MESSAGE(
63 "unexpected value #7 from RNG",
64 uint16_t(0x4500), value
67 CPPUNIT_ASSERT_EQUAL_MESSAGE(
68 "unexpected value #8 from RNG",
69 uint16_t(0x0000), value
71 CPPUNIT_ASSERT_EQUAL_MESSAGE(
72 "unexpected value #9 from RNG",
73 uint16_t(0x0000), value
76 CPPUNIT_ASSERT_EQUAL_MESSAGE(
77 "unexpected value #10 from RNG",
78 uint16_t(0x0000), value
81 CPPUNIT_ASSERT_EQUAL_MESSAGE(
82 "unexpected value #11 from RNG",
83 uint16_t(0x0000), value
86 CPPUNIT_ASSERT_EQUAL_MESSAGE(
87 "unexpected value #12 from RNG",
88 uint16_t(0x2E70), value
91 CPPUNIT_ASSERT_EQUAL_MESSAGE(
92 "unexpected value #13 from RNG",
93 uint16_t(0x0000), value
96 CPPUNIT_ASSERT_EQUAL_MESSAGE(
97 "unexpected value #14 from RNG",
98 uint16_t(0x0000), value
101 CPPUNIT_ASSERT_EQUAL_MESSAGE(
102 "unexpected value #15 from RNG",
103 uint16_t(0x0000), value
106 CPPUNIT_ASSERT_EQUAL_MESSAGE(
107 "unexpected value #16 from RNG",
108 uint16_t(0x1011), value
111 CPPUNIT_ASSERT_EQUAL_MESSAGE(
112 "unexpected value #17 from RNG",
113 uint16_t(0x0000), value
116 CPPUNIT_ASSERT_EQUAL_MESSAGE(
117 "unexpected value #18 from RNG",
118 uint16_t(0x0000), value
121 CPPUNIT_ASSERT_EQUAL_MESSAGE(
122 "unexpected value #19 from RNG",
123 uint16_t(0xB000), value
126 CPPUNIT_ASSERT_EQUAL_MESSAGE(
127 "unexpected value #20 from RNG",
128 uint16_t(0x0B0B), value
131 CPPUNIT_ASSERT_EQUAL_MESSAGE(
132 "unexpected value #21 from RNG",
133 uint16_t(0x0000), value
136 CPPUNIT_ASSERT_EQUAL_MESSAGE(
137 "unexpected value #22 from RNG",
138 uint16_t(0x0000), value
141 CPPUNIT_ASSERT_EQUAL_MESSAGE(
142 "unexpected value #23 from RNG",
143 uint16_t(0x1500), value
146 CPPUNIT_ASSERT_EQUAL_MESSAGE(
147 "unexpected value #24 from RNG",
148 uint16_t(0x0454), value
151 CPPUNIT_ASSERT_EQUAL_MESSAGE(
152 "unexpected value #25 from RNG",
153 uint16_t(0x0000), value
156 CPPUNIT_ASSERT_EQUAL_MESSAGE(
157 "unexpected value #26 from RNG",
158 uint16_t(0x0000), value
161 CPPUNIT_ASSERT_EQUAL_MESSAGE(
162 "unexpected value #27 from RNG",
163 uint16_t(0xC970), value
166 CPPUNIT_ASSERT_EQUAL_MESSAGE(
167 "unexpected value #28 from RNG",
168 uint16_t(0x02E5), value
171 CPPUNIT_ASSERT_EQUAL_MESSAGE(
172 "unexpected value #29 from RNG",
173 uint16_t(0x0000), value
176 CPPUNIT_ASSERT_EQUAL_MESSAGE(
177 "unexpected value #30 from RNG",
178 uint16_t(0x0000), value
181 CPPUNIT_ASSERT_EQUAL_MESSAGE(
182 "unexpected value #31 from RNG",
183 uint16_t(0x0101), value
186 CPPUNIT_ASSERT_EQUAL_MESSAGE(
187 "unexpected value #32 from RNG",
188 uint16_t(0x0100), value
192 void StabilityTest::testSimplex() {
193 SimplexNoise noise(0);
195 Assert(noise, glm::vec3(0.0f, 0.0f, 0.0f), 0.0f);
196 Assert(noise, glm::vec3(0.0f, 0.0f, 1.0f), 0.652221322059631f);
197 Assert(noise, glm::vec3(0.0f, 1.0f, 0.0f), 0.867977976799011f);
198 Assert(noise, glm::vec3(0.0f, 1.0f, 1.0f), -0.107878111302853f);
199 Assert(noise, glm::vec3(1.0f, 0.0f, 0.0f), -0.107878260314465f);
200 Assert(noise, glm::vec3(1.0f, 0.0f, 1.0f), -6.31356940061778e-08f);
201 Assert(noise, glm::vec3(1.0f, 1.0f, 0.0f), -0.107878245413303f);
202 Assert(noise, glm::vec3(1.0f, 1.0f, 1.0f), 0.0f);
204 Assert(noise, glm::vec3( 0.0f, 0.0f, -1.0f), -0.107878483831882f);
205 Assert(noise, glm::vec3( 0.0f, -1.0f, 0.0f), -0.760099768638611f);
206 Assert(noise, glm::vec3( 0.0f, -1.0f, -1.0f), 0.0f);
207 Assert(noise, glm::vec3(-1.0f, 0.0f, 0.0f), 0.760099768638611f);
208 Assert(noise, glm::vec3(-1.0f, 0.0f, -1.0f), 0.0f);
209 Assert(noise, glm::vec3(-1.0f, -1.0f, 0.0f), -0.107878118753433f);
210 Assert(noise, glm::vec3(-1.0f, -1.0f, -1.0f), 0.0f);
213 void StabilityTest::Assert(
214 const SimplexNoise &noise,
215 const glm::vec3 &position,
219 msg << "unexpected simplex noise value at " << position;
220 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
222 expected, noise(position), numeric_limits<float>::epsilon()