-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stats.cpp
76 lines (59 loc) · 1.56 KB
/
test_stats.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
#include "stats.hpp"
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>
void poc() {
Stats s(0, 0, 0);
for (size_t i = 0; i < Stats::SIZE; ++i) {
for (size_t j = 0; j < i * 2; ++j)
s.inc();
s.move(0, 1);
s.move(1, 1);
s.move(2, 1);
}
s.get();
}
void print_hex(std::ostream &out, const uint8_t *data, size_t size) {
for (size_t i = 0; i < size; ++i)
out << std::hex << std::setfill('0') << std::setw(2) << int(data[i]);
}
#define CONSTRUCTOR 0
#define MOVE 0
#define INC 1
#define DEC 2
#define GET 3
template<typename T>
void push(std::vector<uint8_t> &data, const T &value) {
auto ptr = reinterpret_cast<const uint8_t *>(&value);
for (size_t i = 0; i < sizeof(T); ++i)
data.push_back(ptr[i]);
}
std::vector<uint8_t> make_hex_poc() {
std::vector<uint8_t> data;
data.push_back(CONSTRUCTOR);
push<size_t>(data, 0);
push<size_t>(data, 0);
push<size_t>(data, 0);
for (size_t i = 0; i < Stats::SIZE; ++i) {
for (size_t j = 0; j < i * 2; ++j)
data.push_back(INC);
data.push_back(MOVE);
push<size_t>(data, 0);
push<int>(data, 1);
data.push_back(MOVE);
push<size_t>(data, 1);
push<int>(data, 1);
data.push_back(MOVE);
push<size_t>(data, 2);
push<int>(data, 1);
}
data.push_back(GET);
return data;
}
int main() {
// poc();
auto data = make_hex_poc();
print_hex(std::cout, &data.front(), data.size());
std::cout << std::endl;
}