1 #include "LocationTest.hpp"
4 #include <glm/gtx/io.hpp>
6 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::LocationTest);
12 void LocationTest::setUp() {
15 void LocationTest::tearDown() {
19 void LocationTest::testSanitize() {
21 RoughLocation loc({ 0, 0, 0 }, { 0, 0, 0 });
24 "sanitize rough zero location",
25 RoughLocation({ 0, 0, 0 }, { 0, 0, 0 }), loc
29 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
32 "sanitize exact zero location",
33 ExactLocation({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f }), loc
37 ExactLocation loc({ 0, 0, 0 }, { 15.9f, 0.0f, 0.0f });
40 "sanitize exact location near upper boundary",
41 ExactLocation({ 0, 0, 0 }, { 15.9f, 0.0f, 0.0f }), loc
45 RoughLocation loc({ 0, 0, 0 }, { 0, 16, 0 });
48 "sanitize rough location",
49 RoughLocation({ 0, 1, 0 }, { 0, 0, 0 }), loc
53 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 16.0f, 0.0f });
56 "sanitize exact location",
57 ExactLocation({ 0, 1, 0 }, { 0.0f, 0.0f, 0.0f }), loc
61 RoughLocation loc({ 0, 0, 0 }, { 0, 0, -1 });
64 "sanitize rough negative location",
65 RoughLocation({ 0, 0, -1 }, { 0, 0, 15 }), loc
69 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, -1.0f });
72 "sanitize exact negative location",
73 ExactLocation({ 0, 0, -1 }, { 0.0f, 0.0f, 15.0f }), loc
77 RoughLocation loc({ 0, 0, 0 }, { 0, 41585, 0 });
80 "sanitize rough really far location",
81 RoughLocation({ 0, 2599, 0 }, { 0, 1, 0 }), loc
85 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 41585.0f, 0.0f });
88 "sanitize exact really far location",
89 ExactLocation({ 0, 2599, 0 }, { 0.0f, 1.0f, 0.0f }), loc
93 RoughLocation loc({ 0, 0, 0 }, { -208005, 0, 0 });
96 "sanitize rough really far negative location",
97 RoughLocation({ -13001, 0, 0 }, { 11, 0, 0 }), loc
101 ExactLocation loc({ 0, 0, 0 }, { -208005.0f, 0.0f, 0.0f });
104 "sanitize exact really far negative location",
105 ExactLocation({ -13001, 0, 0 }, { 11.0f, 0.0f, 0.0f }), loc
109 RoughLocation loc({ 0, -2, 0 }, { 0, 16, 0 });
112 "sanitize rough location with non-zero chunk",
113 RoughLocation({ 0, -1, 0 }, { 0, 0, 0 }), loc
117 ExactLocation loc({ 0, -2, 0 }, { 0.0f, 16.0f, 0.0f });
120 "sanitize exact location with non-zero chunk",
121 ExactLocation({ 0, -1, 0 }, { 0.0f, 0.0f, 0.0f }), loc
125 RoughLocation loc({ 0, 0, 5 }, { 0, 0, -33 });
128 "sanitize rough negative location with non-zero chunk",
129 RoughLocation({ 0, 0, 2 }, { 0, 0, 15 }), loc
133 ExactLocation loc({ 0, 0, 5 }, { 0.0f, 0.0f, -33.0f });
136 "sanitize exact negative location with non-zero chunk",
137 ExactLocation({ 0, 0, 2 }, { 0.0f, 0.0f, 15.0f }), loc
142 void LocationTest::testAbsolute() {
144 RoughLocation loc({ 0, 0, 0 }, { 0, 0, 0 });
146 "absolute of rough zero location",
147 RoughLocation::Fine(0, 0, 0), loc.Absolute()
151 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
153 "absolute of exact zero location",
154 ExactLocation::Fine(0.0f, 0.0f, 0.0f), loc.Absolute()
158 RoughLocation loc({ 0, 2, 0 }, { 0, 5, 0 });
160 "absolute of rough location",
161 RoughLocation::Fine(0, 37, 0), loc.Absolute()
165 ExactLocation loc({ 0, 2, 0 }, { 0.0f, 5.0f, 0.0f });
167 "absolute of exact location",
168 ExactLocation::Fine(0.0f, 37.0f, 0.0f), loc.Absolute()
172 RoughLocation loc({ 0, 0, -2 }, { 0, 0, 5 });
174 "absolute of rough negative location",
175 RoughLocation::Fine(0, 0, -27), loc.Absolute()
179 ExactLocation loc({ 0, 0, -2 }, { 0.0f, 0.0f, 5.0f });
181 "absolute of exact negative location",
182 ExactLocation::Fine(0.0f, 0.0f, -27.0f), loc.Absolute()
187 void LocationTest::testRelative() {
188 glm::ivec3 base(0, 0, 0);
190 RoughLocation loc({ 0, 0, 0 }, { 0, 0, 0 });
192 "relative of rough zero location with zero base",
193 RoughLocation::Fine(0, 0, 0), loc.Relative(base).Absolute()
197 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
199 "relative of exact zero location with zero base",
200 ExactLocation::Fine(0.0f, 0.0f, 0.0f), loc.Relative(base).Absolute()
204 RoughLocation loc({ 0, 2, 0 }, { 0, 5, 0 });
206 "relative of rough location with zero base",
207 RoughLocation::Fine(0, 37, 0), loc.Relative(base).Absolute()
211 ExactLocation loc({ 0, 2, 0 }, { 0.0f, 5.0f, 0.0f });
213 "relative of exact location with zero base",
214 ExactLocation::Fine(0.0f, 37.0f, 0.0f), loc.Relative(base).Absolute()
218 RoughLocation loc({ 0, 0, -2 }, { 0, 0, 5 });
220 "relative of rough negative location with zero base",
221 RoughLocation::Fine(0, 0, -27), loc.Relative(base).Absolute()
225 ExactLocation loc({ 0, 0, -2 }, { 0.0f, 0.0f, 5.0f });
227 "relative of exact negative location with zero base",
228 ExactLocation::Fine(0.0f, 0.0f, -27.0f), loc.Relative(base).Absolute()
232 base = glm::ivec3(0, 1, 0);
234 RoughLocation loc({ 0, 0, 0 }, { 0, 0, 0 });
236 "relative of rough zero location with positive base",
237 RoughLocation::Fine(0, -16, 0), loc.Relative(base).Absolute()
241 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
243 "relative of exact zero location with positive base",
244 ExactLocation::Fine(0.0f, -16.0f, 0.0f), loc.Relative(base).Absolute()
248 RoughLocation loc({ 0, 2, 0 }, { 0, 5, 0 });
250 "relative of rough location with positive base",
251 RoughLocation::Fine(0, 21, 0), loc.Relative(base).Absolute()
255 ExactLocation loc({ 0, 2, 0 }, { 0.0f, 5.0f, 0.0f });
257 "relative of exact location with positive base",
258 ExactLocation::Fine(0.0f, 21.0f, 0.0f), loc.Relative(base).Absolute()
262 RoughLocation loc({ 0, 0, -2 }, { 0, 0, 5 });
264 "relative of rough negative location with positive base",
265 RoughLocation::Fine(0, -16, -27), loc.Relative(base).Absolute()
269 ExactLocation loc({ 0, 0, -2 }, { 0.0f, 0.0f, 5.0f });
271 "relative of exact negative location with positive base",
272 ExactLocation::Fine(0.0f, -16.0f, -27.0f), loc.Relative(base).Absolute()
276 base = glm::ivec3(-2, 0, 0);
278 RoughLocation loc({ 0, 0, 0 }, { 0, 0, 0 });
280 "relative of rough zero location with negative base",
281 RoughLocation::Fine(32, 0, 0), loc.Relative(base).Absolute()
285 ExactLocation loc({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
287 "relative of exact zero location with negative base",
288 ExactLocation::Fine(32.0f, 0.0f, 0.0f), loc.Relative(base).Absolute()
292 RoughLocation loc({ 0, 2, 0 }, { 0, 5, 0 });
294 "relative of rough location with negative base",
295 RoughLocation::Fine(32, 37, 0), loc.Relative(base).Absolute()
299 ExactLocation loc({ 0, 2, 0 }, { 0.0f, 5.0f, 0.0f });
301 "relative of exact location with negative base",
302 ExactLocation::Fine(32.0f, 37.0f, 0.0f), loc.Relative(base).Absolute()
306 RoughLocation loc({ 0, 0, -2 }, { 0, 0, 5 });
308 "relative of rough negative location with negative base",
309 RoughLocation::Fine(32, 0, -27), loc.Relative(base).Absolute()
313 ExactLocation loc({ 0, 0, -2 }, { 0.0f, 0.0f, 5.0f });
315 "relative of exact negative location with negative base",
316 ExactLocation::Fine(32.0f, 0.0f, -27.0f), loc.Relative(base).Absolute()
321 void LocationTest::testDifference() {
323 RoughLocation a({ 0, 0, 0 }, { 0, 0, 0 });
324 RoughLocation b({ 0, 0, 0 }, { 0, 0, 0 });
326 "difference between rough zero locations",
327 RoughLocation::Fine(0, 0, 0), a.Difference(b).Absolute()
331 ExactLocation a({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
332 ExactLocation b({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
334 "difference between exact zero locations",
335 ExactLocation::Fine(0.0f, 0.0f, 0.0f), a.Difference(b).Absolute()
339 RoughLocation a({ 0, 0, 0 }, { 5, 0, 0 });
340 RoughLocation b({ 0, 0, 0 }, { 0, 0, 0 });
342 "difference between rough locations",
343 RoughLocation::Fine(5, 0, 0), a.Difference(b).Absolute()
347 ExactLocation a({ 0, 0, 0 }, { 5.0f, 0.0f, 0.0f });
348 ExactLocation b({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
350 "difference between exact locations",
351 ExactLocation::Fine(5.0f, 0.0f, 0.0f), a.Difference(b).Absolute()
355 RoughLocation a({ 0, 0, 0 }, { 0, 0, 0 });
356 RoughLocation b({ 0, 0, 0 }, { 0, 5, 0 });
358 "difference between rough locations",
359 RoughLocation::Fine(0, -5, 0), a.Difference(b).Absolute()
363 ExactLocation a({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
364 ExactLocation b({ 0, 0, 0 }, { 0.0f, 5.0f, 0.0f });
366 "difference between exact locations",
367 ExactLocation::Fine(0.0f, -5.0f, 0.0f), a.Difference(b).Absolute()
371 RoughLocation a({ 0, 0, 0 }, { 0, 0, 0 });
372 RoughLocation b({ 0, 0, 0 }, { 0, 0, -3 });
374 "difference between rough locations",
375 RoughLocation::Fine(0, 0, 3), a.Difference(b).Absolute()
379 ExactLocation a({ 0, 0, 0 }, { 0.0f, 0.0f, 0.0f });
380 ExactLocation b({ 0, 0, 0 }, { 0.0f, 0.0f, -3.0f });
382 "difference between exact locations",
383 ExactLocation::Fine(0.0f, 0.0f, 3.0f), a.Difference(b).Absolute()
387 RoughLocation a({ 1, 0, -1 }, { 5, 14, 9 });
388 RoughLocation b({ 0, 2, -1 }, { 3, 2, 0 });
390 "difference between rough locations",
391 RoughLocation::Fine(18, -20, 9), a.Difference(b).Absolute()
395 ExactLocation a({ 1, 0, -1 }, { 5.0f, 14.0f, 9.0f });
396 ExactLocation b({ 0, 2, -1 }, { 3.0f, 2.0f, 0.0f });
398 "difference between exact locations",
399 ExactLocation::Fine(18.0f, -20.0f, 9.0f), a.Difference(b).Absolute()
405 void LocationTest::AssertEqual(
406 const std::string &msg,
407 const glm::ivec3 &expected,
408 const glm::ivec3 &actual
410 CPPUNIT_ASSERT_EQUAL_MESSAGE(
414 CPPUNIT_ASSERT_EQUAL_MESSAGE(
418 CPPUNIT_ASSERT_EQUAL_MESSAGE(
424 void LocationTest::AssertEqual(
425 const std::string &msg,
426 const glm::vec3 &expected,
427 const glm::vec3 &actual
429 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
431 expected.x, actual.x, std::numeric_limits<float>::epsilon()
433 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
435 expected.y, actual.y, std::numeric_limits<float>::epsilon()
437 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
439 expected.z, actual.z, std::numeric_limits<float>::epsilon()
443 void LocationTest::AssertEqual(
444 const std::string &msg,
445 const RoughLocation &expected,
446 const RoughLocation &actual
450 expected.chunk, actual.chunk
454 expected.block, actual.block
458 void LocationTest::AssertEqual(
459 const std::string &msg,
460 const ExactLocation &expected,
461 const ExactLocation &actual
465 expected.chunk, actual.chunk
469 expected.block, actual.block