-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
85 lines (71 loc) · 2.38 KB
/
test.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "bufradixsort.h"
#include <cstdint>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <memory>
#include <random>
template<class A>
static void print3(A data, A work1, A work2, size_t len) {
std::cout << std::hex;
std::cout << "INPUT" << std::endl;
for (size_t i = 0; i < len; i++) {
std::cout << std::setfill('0') << std::setw(16) << data[i] << std::endl;
}
std::cout << "RESULT bufradixsort" << std::endl;
for (size_t i = 0; i < len; i++) {
std::cout << std::setfill('0') << std::setw(16) << work1[i] << std::endl;
}
std::cout << "RESULT std::sort" << std::endl;
for (size_t i = 0; i < len; i++) {
std::cout << std::setfill('0') << std::setw(16) << work2[i] << std::endl;
}
}
static bool test_uint32(std::mt19937 gen, bool verbose) {
std::cout << "uint32 test" << std::endl;
size_t len = 20000;
std::vector<uint32_t> data(len);
std::vector<uint32_t> work1(len);
std::vector<uint32_t> work2(len);
for (size_t i = 0; i < len; i++)
data[i] = gen();
std::copy(data.begin(), data.end(), work1.begin());
bufradix_layout_t elem_layout[] = {{0, BUFRADIX_LAYOUT_UINT, 32}, {0, BUFRADIX_LAYOUT_END, 0}};
bufradixsort(work1.data(), work2.data(), len, elem_layout);
std::copy(data.begin(), data.end(), work2.begin());
std::sort(work2.begin(), work2.end());
bool result = !std::equal(work1.begin(), work1.end(), work2.begin());
if (result && verbose) print3(data, work1, work2, len);
return result;
}
static bool test_int32(std::mt19937 gen, bool verbose) {
std::cout << "int32 test" << std::endl;
size_t len = 20000;
std::vector<int32_t> data(len);
std::vector<int32_t> work1(len);
std::vector<int32_t> work2(len);
for (size_t i = 0; i < len; i++)
data[i] = gen();
std::copy(data.begin(), data.end(), work1.begin());
bufradix_layout_t elem_layout[] = {{0, BUFRADIX_LAYOUT_INT, 32}, {0, BUFRADIX_LAYOUT_END, 0}};
bufradixsort(work1.data(), work2.data(), len, elem_layout);
std::copy(data.begin(), data.end(), work2.begin());
std::sort(work2.begin(), work2.end());
bool result = !std::equal(work1.begin(), work1.end(), work2.begin());
if (result && verbose) print3(data, work1, work2, len);
return result;
}
static bool(*tests[])(std::mt19937, bool) = {
test_uint32,
test_int32,
NULL
};
int main() {
std::mt19937 gen(3145);
for (auto test_p = tests; *test_p; test_p++) {
if ((*test_p)(gen, false)) {
std::cout << "fail" << std::endl;
}
}
return 0;
}