]> git.localhorst.tv Git - blank.git/blob - tst/rand/StabilityTest.cpp
(shabby) client side handling of messages
[blank.git] / tst / rand / StabilityTest.cpp
1 #include "StabilityTest.hpp"
2
3 #include "rand/GaloisLFSR.hpp"
4 #include "rand/SimplexNoise.hpp"
5
6 #include <cstdint>
7 #include <string>
8 #include <sstream>
9 #include <glm/gtx/io.hpp>
10
11 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::StabilityTest);
12
13 using namespace std;
14
15
16 namespace blank {
17 namespace test {
18
19 void StabilityTest::setUp() {
20
21 }
22
23 void StabilityTest::tearDown() {
24
25 }
26
27
28 void StabilityTest::testRNG() {
29         GaloisLFSR random(0);
30         uint16_t value;
31         random(value);
32         CPPUNIT_ASSERT_EQUAL_MESSAGE(
33                 "unexpected value #1 from RNG",
34                 uint16_t(0x0000), value
35         );
36         random(value);
37         CPPUNIT_ASSERT_EQUAL_MESSAGE(
38                 "unexpected value #2 from RNG",
39                 uint16_t(0x0000), value
40         );
41         random(value);
42         CPPUNIT_ASSERT_EQUAL_MESSAGE(
43                 "unexpected value #3 from RNG",
44                 uint16_t(0xB000), value
45         );
46         random(value);
47         CPPUNIT_ASSERT_EQUAL_MESSAGE(
48                 "unexpected value #4 from RNG",
49                 uint16_t(0x0000), value
50         );
51         random(value);
52         CPPUNIT_ASSERT_EQUAL_MESSAGE(
53                 "unexpected value #5 from RNG",
54                 uint16_t(0x0000), value
55         );
56         random(value);
57         CPPUNIT_ASSERT_EQUAL_MESSAGE(
58                 "unexpected value #6 from RNG",
59                 uint16_t(0x0000), value
60         );
61         random(value);
62         CPPUNIT_ASSERT_EQUAL_MESSAGE(
63                 "unexpected value #7 from RNG",
64                 uint16_t(0x4500), value
65         );
66         random(value);
67         CPPUNIT_ASSERT_EQUAL_MESSAGE(
68                 "unexpected value #8 from RNG",
69                 uint16_t(0x0000), value
70         );
71         CPPUNIT_ASSERT_EQUAL_MESSAGE(
72                 "unexpected value #9 from RNG",
73                 uint16_t(0x0000), value
74         );
75         random(value);
76         CPPUNIT_ASSERT_EQUAL_MESSAGE(
77                 "unexpected value #10 from RNG",
78                 uint16_t(0x0000), value
79         );
80         random(value);
81         CPPUNIT_ASSERT_EQUAL_MESSAGE(
82                 "unexpected value #11 from RNG",
83                 uint16_t(0x0000), value
84         );
85         random(value);
86         CPPUNIT_ASSERT_EQUAL_MESSAGE(
87                 "unexpected value #12 from RNG",
88                 uint16_t(0x2E70), value
89         );
90         random(value);
91         CPPUNIT_ASSERT_EQUAL_MESSAGE(
92                 "unexpected value #13 from RNG",
93                 uint16_t(0x0000), value
94         );
95         random(value);
96         CPPUNIT_ASSERT_EQUAL_MESSAGE(
97                 "unexpected value #14 from RNG",
98                 uint16_t(0x0000), value
99         );
100         random(value);
101         CPPUNIT_ASSERT_EQUAL_MESSAGE(
102                 "unexpected value #15 from RNG",
103                 uint16_t(0x0000), value
104         );
105         random(value);
106         CPPUNIT_ASSERT_EQUAL_MESSAGE(
107                 "unexpected value #16 from RNG",
108                 uint16_t(0x1011), value
109         );
110         random(value);
111         CPPUNIT_ASSERT_EQUAL_MESSAGE(
112                 "unexpected value #17 from RNG",
113                 uint16_t(0x0000), value
114         );
115         random(value);
116         CPPUNIT_ASSERT_EQUAL_MESSAGE(
117                 "unexpected value #18 from RNG",
118                 uint16_t(0x0000), value
119         );
120         random(value);
121         CPPUNIT_ASSERT_EQUAL_MESSAGE(
122                 "unexpected value #19 from RNG",
123                 uint16_t(0xB000), value
124         );
125         random(value);
126         CPPUNIT_ASSERT_EQUAL_MESSAGE(
127                 "unexpected value #20 from RNG",
128                 uint16_t(0x0B0B), value
129         );
130         random(value);
131         CPPUNIT_ASSERT_EQUAL_MESSAGE(
132                 "unexpected value #21 from RNG",
133                 uint16_t(0x0000), value
134         );
135         random(value);
136         CPPUNIT_ASSERT_EQUAL_MESSAGE(
137                 "unexpected value #22 from RNG",
138                 uint16_t(0x0000), value
139         );
140         random(value);
141         CPPUNIT_ASSERT_EQUAL_MESSAGE(
142                 "unexpected value #23 from RNG",
143                 uint16_t(0x1500), value
144         );
145         random(value);
146         CPPUNIT_ASSERT_EQUAL_MESSAGE(
147                 "unexpected value #24 from RNG",
148                 uint16_t(0x0454), value
149         );
150         random(value);
151         CPPUNIT_ASSERT_EQUAL_MESSAGE(
152                 "unexpected value #25 from RNG",
153                 uint16_t(0x0000), value
154         );
155         random(value);
156         CPPUNIT_ASSERT_EQUAL_MESSAGE(
157                 "unexpected value #26 from RNG",
158                 uint16_t(0x0000), value
159         );
160         random(value);
161         CPPUNIT_ASSERT_EQUAL_MESSAGE(
162                 "unexpected value #27 from RNG",
163                 uint16_t(0xC970), value
164         );
165         random(value);
166         CPPUNIT_ASSERT_EQUAL_MESSAGE(
167                 "unexpected value #28 from RNG",
168                 uint16_t(0x02E5), value
169         );
170         random(value);
171         CPPUNIT_ASSERT_EQUAL_MESSAGE(
172                 "unexpected value #29 from RNG",
173                 uint16_t(0x0000), value
174         );
175         random(value);
176         CPPUNIT_ASSERT_EQUAL_MESSAGE(
177                 "unexpected value #30 from RNG",
178                 uint16_t(0x0000), value
179         );
180         random(value);
181         CPPUNIT_ASSERT_EQUAL_MESSAGE(
182                 "unexpected value #31 from RNG",
183                 uint16_t(0x0101), value
184         );
185         random(value);
186         CPPUNIT_ASSERT_EQUAL_MESSAGE(
187                 "unexpected value #32 from RNG",
188                 uint16_t(0x0100), value
189         );
190 }
191
192 void StabilityTest::testSimplex() {
193         SimplexNoise noise(0);
194
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);
203
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);
211 }
212
213 void StabilityTest::Assert(
214         const SimplexNoise &noise,
215         const glm::vec3 &position,
216         float expected
217 ) {
218         stringstream msg;
219         msg << "unexpected simplex noise value at " << position;
220         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
221                 msg.str(),
222                 expected, noise(position), numeric_limits<float>::epsilon()
223         );
224 }
225
226 }
227 }