-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutest_c.cpp
196 lines (194 loc) · 8.51 KB
/
utest_c.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* SPDX-License-Identifier: GPL-3.0-or-later
SPDX-FileCopyrightText: Copyright 2023 Erez Geva */
#include <gtest/gtest.h>
#define ST_USE_C
#include "nsl_statistics.h"
TEST(nslCTest, stat)
{
struct nsl_stats s0, *s = &s0;
nsl_stats_init(s);
EXPECT_EQ(nsl_stats_get_num_elems(s), 0);
EXPECT_EQ(nsl_stats_get_min(s), 0x7FFFFFFFFFFFFFFFLL);
EXPECT_EQ(nsl_stats_get_max(s), -0x8000000000000000LL);
EXPECT_EQ(nsl_stats_get_mean(s), 0);
EXPECT_DOUBLE_EQ(nsl_stats_get_sq(s), 0);
EXPECT_DOUBLE_EQ(nsl_stats_get_sd(s), 0);
nsl_stats_add_elem(s, 10);
EXPECT_EQ(nsl_stats_get_num_elems(s), 1);
EXPECT_EQ(nsl_stats_get_min(s), 10);
EXPECT_EQ(nsl_stats_get_max(s), 10);
EXPECT_EQ(nsl_stats_get_mean(s), 10);
EXPECT_DOUBLE_EQ(nsl_stats_get_sq(s), 100);
EXPECT_TRUE(std::isnan(nsl_stats_get_sd(s)));
nsl_stats_add_elem(s, 20);
EXPECT_EQ(nsl_stats_get_num_elems(s), 2);
EXPECT_EQ(nsl_stats_get_min(s), 10);
EXPECT_EQ(nsl_stats_get_max(s), 20);
EXPECT_EQ(nsl_stats_get_mean(s), 15);
EXPECT_DOUBLE_EQ(nsl_stats_get_sq(s), 250);
EXPECT_DOUBLE_EQ(nsl_stats_get_sd(s), 7.0710678118654755);
nsl_stats_add_elem(s, 30);
EXPECT_EQ(nsl_stats_get_num_elems(s), 3);
EXPECT_EQ(nsl_stats_get_min(s), 10);
EXPECT_EQ(nsl_stats_get_max(s), 30);
EXPECT_EQ(nsl_stats_get_mean(s), 20);
EXPECT_DOUBLE_EQ(nsl_stats_get_sq(s), 466.66666666666669);
EXPECT_DOUBLE_EQ(nsl_stats_get_sd(s), 10);
}
TEST(nslCTest, vec)
{
struct nsl_vec_stats v0, *v = &v0;
nsl_vec_stats_init(v, 10,5,10);
EXPECT_EQ(nsl_vec_stats_get_start(v), 10);
EXPECT_EQ(nsl_vec_stats_get_end(v), 60);
EXPECT_EQ(nsl_vec_stats_get_step(v), 10);
EXPECT_EQ(nsl_vec_stats_get_size(v), 5);
// add elements
EXPECT_EQ(nsl_vec_stats_get_below(v), 0);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 9);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 10);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 19);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 20);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 29);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 30);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 39);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 40);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 49);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 50);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 59);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 0);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 0);
nsl_vec_stats_add_elem(v, 60);
EXPECT_EQ(nsl_vec_stats_get_below(v), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 40), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 50), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v, 60), 1);
// Copy vector
struct nsl_vec_stats v02, *v2 = &v02;
nsl_vec_stats_copy(v2, v);
EXPECT_EQ(nsl_vec_stats_get_start(v2), 10);
EXPECT_EQ(nsl_vec_stats_get_end(v2), 60);
EXPECT_EQ(nsl_vec_stats_get_step(v2), 10);
EXPECT_EQ(nsl_vec_stats_get_size(v2), 5);
EXPECT_EQ(nsl_vec_stats_get_below(v2), 1);
EXPECT_EQ(nsl_vec_stats_get_above(v2), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 0), 1);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 10), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 20), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 30), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 40), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 50), 2);
EXPECT_EQ(nsl_vec_stats_get_value(v2, 60), 1);
nsl_vec_stats_remove(v);
nsl_vec_stats_remove(v2);
}