-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhilbert_test.cc
More file actions
47 lines (39 loc) · 1.73 KB
/
Copy pathhilbert_test.cc
File metadata and controls
47 lines (39 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
#include "hilbert.h"
#include "hilbert_cs.h"
#include "hilbert_ref_impl.h"
int main(int argc, char **argv) {
uint64_t max_order = (argc > 1) ? std::atoi(argv[1]) : 16;
[&]<std::size_t... Is>(std::index_sequence<Is...>) {
(
[&] {
constexpr uint64_t order = static_cast<uint64_t>(Is + 1);
if (order > max_order)
return;
std::cout << "ORDER: " << order << std::endl;
std::vector<uint32_t> table = make_table<order>();
std::vector<uint32_t> table_cs = make_table_cs<order>();
std::vector<uint32_t> table_ref = make_table_ref(order);
uint64_t dim = 1 << order;
uint64_t num_indices = dim * dim;
for (uint64_t i {}; i < num_indices; i++) {
if (table[i] != table_ref[i]) {
std::cout << "Test failed for index " << i << std::endl;
std::cout << "From megablock algorithm: " << table[i] << std::endl;
std::cout << "From ref: " << table_ref[i] << std::endl;
break;
} else if (table_cs[i] != table_ref[i]) {
std::cout << "Test failed for index " << i << std::endl;
std::cout << "From complement-and-swap algorithm: " << table_cs[i] << std::endl;
std::cout << "From ref: " << table_ref[i] << std::endl;
break;
}
}
}(),
...);
}(std::make_index_sequence<16>()); // [0, 16) gets offset to [1, 16]
}