-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
116 lines (102 loc) · 1.88 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "TrendCalculator.hpp"
#include <string>
#include <vector>
#include <cstdint> // uint32_t, etc
#include <cinttypes> // PRIu32, etc
#include <cstdio>
struct TestUpdate
{
TestUpdate(uint32_t value, uint64_t now) :
value(value), now(now)
{
}
uint32_t value{ 0u };
uint64_t now{ 0u };
};
struct Test
{
Test(std::string name, std::vector<TestUpdate> updates) :
name(name), updates(updates)
{
}
std::string name;
std::vector<TestUpdate> updates;
};
int main(int argc, char* argv[])
{
std::vector<Test> tests {
{
"1", // name
{ // updates
// value, now
{ 1000, 0 },
{ 500, 500 },
{ 500, 1000 },
{ 500, 1500 },
{ 500, 2000 },
{ 500, 2500 },
{ 500, 3000 },
{ 500, 3500 },
{ 500, 4000 },
{ 500, 4500 },
{ 1000, 5000 }
}
},
{
"2", // name
{ // updates
// value, now
{ 1000, 0 },
{ 500, 1000 },
{ 500, 2000 },
{ 500, 3000 },
{ 500, 4000 },
{ 1000, 5000 }
}
},
{
"3", // name
{ // updates
// value, now
{ 1000, 0 },
{ 900, 1000 },
{ 800, 2000 },
{ 700, 3000 },
{ 600, 4000 },
{ 500, 5000 },
{ 400, 6000 },
{ 300, 7000 },
{ 200, 8000 },
{ 100, 9000 },
{ 100, 10000 },
{ 100, 11000 },
{ 100, 12000 },
{ 100, 13000 },
{ 100, 14000 },
{ 100, 15000 },
{ 100, 16000 },
{ 100, 17000 },
{ 100, 18000 },
{ 100, 19000 },
{ 100, 20000 }
}
}
};
for (auto& test : tests)
{
printf(">>> test %s:\n", test.name.c_str());
TrendCalculator trend;
for (auto& update : test.updates)
{
trend.Update(update.value, update.now);
printf(
" trend.Update(value:%" PRIu32 ", now:%" PRIu64 ") [trend value: %" PRIu32 "]\n",
update.value,
update.now,
trend.GetValue());
}
printf("\n");
}
printf(">>> done\n");
return 0;
}