8#ifndef ZMORTON_UNIT_TESTS_HPP_
9#define ZMORTON_UNIT_TESTS_HPP_
11#define BOOST_TEST_DYN_LINK
12#include <boost/test/unit_test.hpp>
14#include "util/zmorton.hpp"
21 check &= (k.get(0) & 0x1) == (res & 0x1);
22 check &= (k.get(0) & (0x1ul << 1)) == ((res & (0x1ul << 2)) >> 1);
23 check &= (k.get(0) & (0x1ul << 2)) == ((res & (0x1ul << 4)) >> 2);
24 check &= (k.get(0) & (0x1ul << 3)) == ((res & (0x1ul << 6)) >> 3);
25 check &= (k.get(0) & (0x1ul << 4)) == ((res & (0x1ul << 8)) >> 4);
26 check &= (k.get(0) & (0x1ul << 5)) == ((res & (0x1ul << 10)) >> 5);
27 check &= (k.get(0) & (0x1ul << 6)) == ((res & (0x1ul << 12)) >> 6);
28 check &= (k.get(0) & (0x1ul << 7)) == ((res & (0x1ul << 14)) >> 7);
29 check &= (k.get(0) & (0x1ul << 8)) == ((res & (0x1ul << 16)) >> 8);
30 check &= (k.get(0) & (0x1ul << 9)) == ((res & (0x1ul << 19)) >> 9);
31 check &= (k.get(0) & (0x1ul << 10)) == ((res & (0x1ul << 20)) >> 10);
32 check &= (k.get(0) & (0x1ul << 11)) == ((res & (0x1ul << 22)) >> 11);
33 check &= (k.get(0) & (0x1ul << 12)) == ((res & (0x1ul << 24)) >> 12);
34 check &= (k.get(0) & (0x1ul << 13)) == ((res & (0x1ul << 26)) >> 13);
35 check &= (k.get(0) & (0x1ul << 14)) == ((res & (0x1ul << 28)) >> 14);
36 check &= (k.get(0) & (0x1ul << 15)) == ((res & (0x1ul << 30)) >> 15);
37 check &= (k.get(0) & (0x1ul << 16)) == ((res & (0x1ul << 32)) >> 16);
38 check &= (k.get(0) & (0x1ul << 17)) == ((res & (0x1ul << 34)) >> 17);
39 check &= (k.get(0) & (0x1ul << 18)) == ((res & (0x1ul << 36)) >> 19);
40 check &= (k.get(0) & (0x1ul << 19)) == ((res & (0x1ul << 38)) >> 19);
41 check &= (k.get(0) & (0x1ul << 20)) == ((res & (0x1ul << 40)) >> 20);
42 check &= (k.get(0) & (0x1ul << 21)) == ((res & (0x1ul << 42)) >> 21);
43 check &= (k.get(0) & (0x1ul << 22)) == ((res & (0x1ul << 44)) >> 22);
44 check &= (k.get(0) & (0x1ul << 23)) == ((res & (0x1ul << 46)) >> 23);
45 check &= (k.get(0) & (0x1ul << 24)) == ((res & (0x1ul << 48)) >> 24);
46 check &= (k.get(0) & (0x1ul << 25)) == ((res & (0x1ul << 50)) >> 25);
47 check &= (k.get(0) & (0x1ul << 26)) == ((res & (0x1ul << 52)) >> 26);
48 check &= (k.get(0) & (0x1ul << 27)) == ((res & (0x1ul << 54)) >> 27);
49 check &= (k.get(0) & (0x1ul << 28)) == ((res & (0x1ul << 56)) >> 28);
50 check &= (k.get(0) & (0x1ul << 29)) == ((res & (0x1ul << 58)) >> 29);
51 check &= (k.get(0) & (0x1ul << 30)) == ((res & (0x1ul << 60)) >> 30);
52 check &= (k.get(0) & (0x1ul << 31)) == ((res & (0x1ul << 62)) >> 31);
56 check &= (k.get(1) & 0x1) == (res & 0x1);
57 check &= (k.get(1) & (0x1ul << 1)) == ((res & (0x1ul << 2)) >> 1);
58 check &= (k.get(1) & (0x1ul << 2)) == ((res & (0x1ul << 4)) >> 2);
59 check &= (k.get(1) & (0x1ul << 3)) == ((res & (0x1ul << 6)) >> 3);
60 check &= (k.get(1) & (0x1ul << 4)) == ((res & (0x1ul << 8)) >> 4);
61 check &= (k.get(1) & (0x1ul << 5)) == ((res & (0x1ul << 10)) >> 5);
62 check &= (k.get(1) & (0x1ul << 6)) == ((res & (0x1ul << 12)) >> 6);
63 check &= (k.get(1) & (0x1ul << 7)) == ((res & (0x1ul << 14)) >> 7);
64 check &= (k.get(1) & (0x1ul << 8)) == ((res & (0x1ul << 16)) >> 8);
65 check &= (k.get(1) & (0x1ul << 9)) == ((res & (0x1ul << 19)) >> 9);
66 check &= (k.get(1) & (0x1ul << 10)) == ((res & (0x1ul << 20)) >> 10);
67 check &= (k.get(1) & (0x1ul << 11)) == ((res & (0x1ul << 22)) >> 11);
68 check &= (k.get(1) & (0x1ul << 12)) == ((res & (0x1ul << 24)) >> 12);
69 check &= (k.get(1) & (0x1ul << 13)) == ((res & (0x1ul << 26)) >> 13);
70 check &= (k.get(1) & (0x1ul << 14)) == ((res & (0x1ul << 28)) >> 14);
71 check &= (k.get(1) & (0x1ul << 15)) == ((res & (0x1ul << 30)) >> 15);
72 check &= (k.get(1) & (0x1ul << 16)) == ((res & (0x1ul << 32)) >> 16);
73 check &= (k.get(1) & (0x1ul << 17)) == ((res & (0x1ul << 34)) >> 17);
74 check &= (k.get(1) & (0x1ul << 18)) == ((res & (0x1ul << 36)) >> 19);
75 check &= (k.get(1) & (0x1ul << 19)) == ((res & (0x1ul << 38)) >> 19);
76 check &= (k.get(1) & (0x1ul << 20)) == ((res & (0x1ul << 40)) >> 20);
77 check &= (k.get(1) & (0x1ul << 21)) == ((res & (0x1ul << 42)) >> 21);
78 check &= (k.get(1) & (0x1ul << 22)) == ((res & (0x1ul << 44)) >> 22);
79 check &= (k.get(1) & (0x1ul << 23)) == ((res & (0x1ul << 46)) >> 23);
80 check &= (k.get(1) & (0x1ul << 24)) == ((res & (0x1ul << 48)) >> 24);
81 check &= (k.get(1) & (0x1ul << 25)) == ((res & (0x1ul << 50)) >> 25);
82 check &= (k.get(1) & (0x1ul << 26)) == ((res & (0x1ul << 52)) >> 26);
83 check &= (k.get(1) & (0x1ul << 27)) == ((res & (0x1ul << 54)) >> 27);
84 check &= (k.get(1) & (0x1ul << 28)) == ((res & (0x1ul << 56)) >> 28);
85 check &= (k.get(1) & (0x1ul << 29)) == ((res & (0x1ul << 58)) >> 29);
86 check &= (k.get(1) & (0x1ul << 30)) == ((res & (0x1ul << 60)) >> 30);
87 check &= (k.get(1) & (0x1ul << 31)) == ((res & (0x1ul << 62)) >> 31);
92BOOST_AUTO_TEST_SUITE( zmorton_suite_test )
94BOOST_AUTO_TEST_CASE( zmorton_linearization_test )
99 BOOST_REQUIRE_EQUAL(lin_zid(key),0);
103 BOOST_REQUIRE_EQUAL(lin_zid(key2),100);
109 BOOST_REQUIRE_EQUAL(lin_zid(key),0);
113 BOOST_REQUIRE_EQUAL(lin_zid(key2),12);
117 BOOST_REQUIRE_EQUAL(lin_zid(key3),13);
121 BOOST_REQUIRE_EQUAL(lin_zid(key4),10);
125 BOOST_REQUIRE_EQUAL(lin_zid(key5),5);
129 size_t res = lin_zid(key6);
131 BOOST_REQUIRE_EQUAL(check(res,key6),
true);
137 BOOST_REQUIRE_EQUAL(res,0xFF);
143 BOOST_REQUIRE_EQUAL(res,0xFFFF);
149 BOOST_REQUIRE_EQUAL(res,0xFFFFFFFF);
153 res = lin_zid(key10);
155 BOOST_REQUIRE_EQUAL(res,0xFFFFFFFFFFFFFFFF);
161 BOOST_REQUIRE_EQUAL(lin_zid(key),0);
165 BOOST_REQUIRE_EQUAL(lin_zid(key2),56);
169 BOOST_REQUIRE_EQUAL(lin_zid(key3),448);
173 BOOST_REQUIRE_EQUAL(lin_zid(key4),3584);
177 BOOST_REQUIRE_EQUAL(lin_zid(key5),(1 << 12) + (1 << 13) + (1 << 14));
181 BOOST_REQUIRE_EQUAL(lin_zid(key6),(1 << 15) + (1 << 16) + (1 << 17));
185 BOOST_REQUIRE_EQUAL(lin_zid(key7),(1 << 18) + (1 << 19) + (1 << 20));
189 BOOST_REQUIRE_EQUAL(lin_zid(key8),(1 << 21) + (1 << 22) + (1 << 23));
193 BOOST_REQUIRE_EQUAL(lin_zid(key9),(1 << 24) + (1 << 25) + (1 << 26));
197 BOOST_REQUIRE_EQUAL(lin_zid(key10),(1 << 27) + (1 << 28) + (1 << 29));
201 BOOST_REQUIRE_EQUAL(lin_zid(key11),(1ul << 30) + (1ul << 31) + (1ul << 32));
205 BOOST_REQUIRE_EQUAL(lin_zid(key12),(1ul << 33) + (1ul << 34) + (1ul << 35));
209 BOOST_REQUIRE_EQUAL(lin_zid(key13),(1ul << 36) + (1ul << 37) + (1ul << 38));
213 BOOST_REQUIRE_EQUAL(lin_zid(key14),(1ul << 39) + (1ul << 40) + (1ul << 41));
217 BOOST_REQUIRE_EQUAL(lin_zid(key15),(1ul << 42) + (1ul << 43) + (1ul << 44));
221 BOOST_REQUIRE_EQUAL(lin_zid(key16),(1ul << 45) + (1ul << 46) + (1ul << 47));
225 BOOST_REQUIRE_EQUAL(lin_zid(key17),(1ul << 48) + (1ul << 49) + (1ul << 50));
229 BOOST_REQUIRE_EQUAL(lin_zid(key18),(1ul << 51) + (1ul << 52) + (1ul << 53));
233 BOOST_REQUIRE_EQUAL(lin_zid(key19),(1ul << 54) + (1ul << 55) + (1ul << 56));
237 BOOST_REQUIRE_EQUAL(lin_zid(key20),(1ul << 57) + (1ul << 58) + (1ul << 59));
241 BOOST_REQUIRE_EQUAL(lin_zid(key21),(1ul << 60) + (1ul << 61) + (1ul << 62));
246BOOST_AUTO_TEST_CASE( zmorton_invlinearization_test )
252 size_t lin = lin_zid(key);
253 invlin_zid(lin,ikey);
255 BOOST_REQUIRE(key == ikey);
261 invlin_zid(lin,ikey2);
263 BOOST_REQUIRE(key2 == ikey2);
270 size_t lin = lin_zid(key);
271 invlin_zid(lin,ikey);
273 BOOST_REQUIRE(key == ikey);
279 invlin_zid(lin,ikey2);
281 BOOST_REQUIRE(key2 == ikey2);
287 invlin_zid(lin,ikey3);
289 BOOST_REQUIRE(key3 == ikey3);
295 invlin_zid(lin,ikey4);
297 BOOST_REQUIRE(key4 == ikey4);
303 invlin_zid(lin,ikey5);
305 BOOST_REQUIRE(key5 == ikey5);
311 invlin_zid(lin,ikey6);
313 BOOST_REQUIRE(key6 == ikey6);
319 invlin_zid(lin,ikey7);
321 BOOST_REQUIRE(key7 == ikey7);
327 invlin_zid(lin,ikey8);
329 BOOST_REQUIRE(key8 == ikey8);
335 invlin_zid(lin,ikey9);
337 BOOST_REQUIRE(key9 == ikey9);
342 lin = lin_zid(key10);
343 invlin_zid(lin,ikey10);
345 BOOST_REQUIRE(key10 == ikey10);
352 size_t lin = lin_zid(key);
353 invlin_zid(lin,ikey);
355 BOOST_REQUIRE(key == ikey);
361 invlin_zid(lin,ikey2);
363 BOOST_REQUIRE(key2 == ikey2);
369 invlin_zid(lin,ikey3);
371 BOOST_REQUIRE(key3 != ikey);
377 invlin_zid(lin,ikey4);
379 BOOST_REQUIRE(key4 == ikey4);
385 invlin_zid(lin,ikey5);
387 BOOST_REQUIRE(key5 == ikey5);
393 invlin_zid(lin,ikey6);
395 BOOST_REQUIRE(key6 == ikey6);
401 invlin_zid(lin,ikey7);
403 BOOST_REQUIRE(key7 == ikey7);
409 invlin_zid(lin,ikey8);
411 BOOST_REQUIRE(key8 == ikey8);
417 invlin_zid(lin,ikey9);
419 BOOST_REQUIRE(key9 == ikey9);
424 lin = lin_zid(key10);
425 invlin_zid(lin,ikey10);
427 BOOST_REQUIRE(key10 == ikey10);
432 lin = lin_zid(key11);
433 invlin_zid(lin,ikey11);
435 BOOST_REQUIRE(key11 == ikey11);
440 lin = lin_zid(key12);
441 invlin_zid(lin,ikey12);
443 BOOST_REQUIRE(key12 == ikey12);
448 lin = lin_zid(key13);
449 invlin_zid(lin,ikey13);
451 BOOST_REQUIRE(key13 == ikey13);
456 lin = lin_zid(key14);
457 invlin_zid(lin,ikey14);
459 BOOST_REQUIRE(key14 == ikey14);
464 lin = lin_zid(key15);
465 invlin_zid(lin,ikey15);
467 BOOST_REQUIRE(key15 == ikey15);
472 lin = lin_zid(key16);
473 invlin_zid(lin,ikey16);
475 BOOST_REQUIRE(key16 == ikey16);
480 lin = lin_zid(key17);
481 invlin_zid(lin,ikey17);
483 BOOST_REQUIRE(key17 == ikey17);
488 lin = lin_zid(key18);
489 invlin_zid(lin,ikey18);
491 BOOST_REQUIRE(key18 == ikey18);
496 lin = lin_zid(key19);
497 invlin_zid(lin,ikey19);
499 BOOST_REQUIRE(key19 == ikey19);
504 lin = lin_zid(key20);
505 invlin_zid(lin,ikey20);
507 BOOST_REQUIRE(key20 == ikey20);
512 lin = lin_zid(key21);
513 invlin_zid(lin,ikey21);
515 BOOST_REQUIRE(key21 == ikey21);
519 for (
unsigned int i = 0 ; i < 100 ; i++)
521 for (
unsigned int j = 0 ; j < 100 ; j++)
523 for (
unsigned int k = 0 ; k < 100 ; k++)
528 lin = lin_zid(key23);
529 invlin_zid(lin,ikey23);
531 match &= key23 == ikey23;
536 BOOST_REQUIRE(match ==
true);
540BOOST_AUTO_TEST_SUITE_END()
grid_key_dx is the key to access any element in the grid