forked from dendibakh/perf-ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.cpp
55 lines (42 loc) · 1.21 KB
/
validate.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
#include "solution.h"
#include <iostream>
#include <stdlib.h>
static int originalCompare(const void *lhs, const void *rhs) {
auto &a = *reinterpret_cast<const S *>(lhs);
auto &b = *reinterpret_cast<const S *>(rhs);
if (a.key1 < b.key1)
return -1;
if (a.key1 > b.key1)
return 1;
if (a.key2 < b.key2)
return -1;
if (a.key2 > b.key2)
return 1;
return 0;
}
static void originalSolution(std::array<S, N> &arr) {
qsort(arr.data(), arr.size(), sizeof(S), originalCompare);
}
int main() {
std::array<S, N> arr;
init(arr);
auto expected = arr;
solution(arr);
originalSolution(expected);
for (size_t i = 0; i < N; i++) {
if (arr[i].key1 != expected[i].key1) {
std::cerr << "Validation Failed. Result[" << i
<< "].key1 = " << arr[i].key1 << ". Expected[" << i
<< "].key1 = " << expected[i].key1 << std::endl;
return 1;
}
if (arr[i].key2 != expected[i].key2) {
std::cerr << "Validation Failed. Result[" << i
<< "].key2 = " << arr[i].key2 << ". Expected[" << i
<< "].key2 = " << expected[i].key2 << std::endl;
return 1;
}
}
std::cout << "Validation Successful" << std::endl;
return 0;
}