| 13 | // Check a 2D encode function for correctness |
| 14 | template <typename morton, typename coord, size_t bits> |
| 15 | static bool check2D_EncodeFunction(const encode_f_2D_wrapper<morton, coord>& function) { |
| 16 | |
| 17 | // Number of bits which can be encoded for each field |
| 18 | static const size_t fieldbits = bits / 2; |
| 19 | |
| 20 | static_assert(bits <= std::numeric_limits<uint64_t>::digits, "Control encoder cannot support > 64 bits."); |
| 21 | static_assert(fieldbits >= 4, "At least 4 bits from each field must fit into 'morton'"); |
| 22 | static_assert(std::numeric_limits<morton>::digits >= 2 * fieldbits, "'morton' must support encoding width"); |
| 23 | static_assert(std::numeric_limits<coord>::digits >= fieldbits, "'coord' must support field width"); |
| 24 | |
| 25 | bool everything_okay = true; |
| 26 | morton computed_code; |
| 27 | uint64_t correct_code; |
| 28 | |
| 29 | // For every set of 4 contiguous bits, test all possible values (0-15), with all other bits cleared |
| 30 | for (size_t offset = 0; offset <= fieldbits - 4; offset++) { |
| 31 | for (coord i = 0; i < 16; i++) { |
| 32 | for (coord j = 0; j < 16; j++) { |
| 33 | coord x = i << offset; |
| 34 | coord y = j << offset; |
| 35 | |
| 36 | correct_code = control_encode(x, y); |
| 37 | computed_code = function.encode(x, y); |
| 38 | if (computed_code != (morton)correct_code) { |
| 39 | everything_okay = false; |
| 40 | std::cout << "\n Incorrect encoding of (" << x << ", " << y << ") in method " << function.description.c_str() << ": " << computed_code << |
| 41 | " != " << (morton)correct_code << "\n"; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | return everything_okay; |
| 47 | } |
| 48 | |
| 49 | // Check a 2D decode function for correctness |
| 50 | template <typename morton, typename coord, size_t bits> |
nothing calls this directly
no test coverage detected