/
ndmaptest.cpp
225 lines (176 loc) · 6.04 KB
/
ndmaptest.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Bring in my package's API, which is what I'm testing
#include "leatra/leatra.hh"
// Bring in gtest
#include <gtest/gtest.h>
ndmap createNdmap1()
{
// values from the cup
double dim1[] = {0.1, 0.125, 0.1, 0.1, 0.09, 0.09, 0.08, 0.05, 0.03, 0.045, 0.045, 0.03, 0.11, 0.12};
double dim2[] = {0.22, 0.4, 0.5, 0.6, 0.6, 0.6, 0.5, 0.11, 0.015, 0.015, 0.015, 0.018, 0.38, 0.35};
double dim3[] = {0.03, 0.02, 0.07, 0.03, 0.04, 0.04, 0.02, 0.05, 0.01, 0.01, 0.01, 0.06, 0.03, 0.07};
ndmap ndm;
ndm.add_deque(std::deque<double>());
ndm.add_deque(std::deque<double>());
ndm.add_deque(std::deque<double>());
for (int i = 0; i < 14; ++i)
{
std::deque<double> point;
point.push_back(dim1[i]);
point.push_back(dim2[i]);
point.push_back(dim3[i]);
ndm.push_back(point);
}
return ndm;
}
ndmap createNdmap2()
{
// values from the coke
double dim1[] = {0.03, 0.05, 0.025, 0.01, 0.01, 0.009, 0.025, 0.025, 0.1, 0.11, 0.11, 0.07, 0.05, 0.05};
double dim2[] = {0.3, 0.2, 0.09, 0.01, 0.01, 0.015, 0.07, 0.48, 0.6, 0.6, 0.6, 0.58, 0.22, 0.23};
double dim3[] = {0.07, 0.05, 0.04, 0.02, 0.02, 0.025, 0.02, 0.025, 0.025, 0.04, 0.04, 0.04, 0.03, 0.06};
ndmap ndm;
ndm.add_deque(std::deque<double>());
ndm.add_deque(std::deque<double>());
ndm.add_deque(std::deque<double>());
for (int i = 0; i < 14; ++i)
{
std::deque<double> point;
point.push_back(dim1[i]);
point.push_back(dim2[i]);
point.push_back(dim3[i]);
ndm.push_back(point);
}
return ndm;
}
ndmapSet createNdmapSet1(std::string name)
{
ndmapSet ndmSet;
ndmSet.set_name(name);
ndmap ndm = createNdmap1();
ndm.set_name(ndmSet.get_name() + "_mean+stdev");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_mean");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_mean-stdev");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_stdev");
ndmSet.add_ndmap(ndm);
return ndmSet;
}
ndmapSet createNdmapSet2(std::string name)
{
ndmapSet ndmSet;
ndmSet.set_name(name);
ndmap ndm = createNdmap2();
ndm.set_name(ndmSet.get_name() + "_mean+stdev");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_mean");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_mean-stdev");
ndmSet.add_ndmap(ndm);
ndm.set_name(ndmSet.get_name() + "_stdev");
ndmSet.add_ndmap(ndm);
return ndmSet;
}
ndmapSetGroup createNdmapSetGroup()
{
ndmapSetGroup group = ndmapSetGroup();
group.add_ndmapSet(createNdmapSet1("cup"));
group.add_ndmapSet(createNdmapSet2("coke"));
return group;
}
TEST(TestSuite, testGetMinMax)
{
ndmap ndm = createNdmap1();
int dim = ndm.get_dim();
ASSERT_EQ(3, dim) << "Dimension of ndmap not equal 3";
double min;
double max;
try
{
ndm.getMinMax(0, min, max);
EXPECT_DOUBLE_EQ(0.03, min) << "Min value of row 0 not equal 0.03";
EXPECT_DOUBLE_EQ(0.125, max) << "Max value of row 0 not equal 0.125";
ndm.getMinMax(1, min, max);
EXPECT_DOUBLE_EQ(0.015, min) << "Min value of row 1 not equal 0.015";
EXPECT_DOUBLE_EQ(0.6, max) << "Max value of row 1 not equal 0.6";
ndm.getMinMax(2, min, max);
EXPECT_DOUBLE_EQ(0.01, min) << "Min value of row 2 not equal 0.01";
EXPECT_DOUBLE_EQ(0.07, max) << "Max value of row 2 not equal 0.07";
}
catch(data_error& e)
{
e.print();
FAIL() << "data_error exception!";
}
}
TEST(TestSuite, testGetDimWithMaxDev)
{
ndmap ndm = createNdmap1();
unsigned int dimWithMaxDev = ndm.getDimWithMaxDev();
EXPECT_EQ(1, dimWithMaxDev) << "Returned dim not the one with max dev";
}
TEST(TestSuite, testGetConstraints)
{
ndmapSet ndmSet = createNdmapSet1("object1");
double threshold1 = 0.0251;
double threshold2 = 0.184;
bool resultArray1[] =
{false, false, false, false, false, false, false, false, true, true, true, false, false, false};
bool resultArray2[] =
{false, false, false, false, false, false, false, true, true, true, true, true, false, false};
std::deque<bool> expectedResult1 = std::deque<bool>();
std::deque<bool> expectedResult2 = std::deque<bool>();
for (int i = 0; i < 14; ++i)
{
expectedResult1.push_back(resultArray1[i]);
expectedResult2.push_back(resultArray2[i]);
}
std::deque<bool> result1 = ndmSet.getConstraints(threshold1);
ASSERT_EQ(expectedResult1.size(), result1.size()) << "Size of result 1 incorrect";
std::deque<bool> result2 = ndmSet.getConstraints(threshold2);
ASSERT_EQ(expectedResult2.size(), result2.size()) << "Size of result 2 incorrect";
for (unsigned int i = 0; i < expectedResult1.size(); ++i) {
EXPECT_EQ(expectedResult1[i], result1[i]) << "Result 1 incorrect";
EXPECT_EQ(expectedResult2[i], result2[i]) << "Result 2 incorrect";
}
}
TEST(TestSuite, testGetConstraintsGroup)
{
// threshold 10% of max deviation
const double THRESHOLD = 0.10;
ndmapSetGroup group = createNdmapSetGroup();
int resultArray[] =
{-1, -1, -1, 1, 1, 1, -1, -1, 0, 0, 0, 0, -1, -1};
std::deque<int> expectedResult = std::deque<int>();
for (int i = 0; i < 14; ++i)
{
expectedResult.push_back(resultArray[i]);
}
std::deque<int> result = group.getConstraints(THRESHOLD);
ASSERT_EQ(expectedResult.size(), result.size()) << "Size of the result incorrect";
for (unsigned int i = 0; i < expectedResult.size(); ++i) {
EXPECT_EQ(expectedResult[i], result[i]) << "Result incorrect";
}
}
TEST(TestSuite, testIsObjectStored)
{
trajectory_lat trajectory;
object coke;
coke.set_name("COCA-COLA-CAN-250ML");
object cup;
cup.set_name("IKEA-CUP-SOLBRAEND-BLUE");
ASSERT_NE(true, trajectory.is_object_stored(coke.get_name())) << "Coke has not yet been stored";
ASSERT_NE(true, trajectory.is_object_stored(cup.get_name())) << "Cup has not yet been stored";
trajectory.add_object(coke);
ASSERT_TRUE(trajectory.is_object_stored(coke.get_name())) << "Coke was stored";
ASSERT_NE(true, trajectory.is_object_stored(cup.get_name())) << "Cup has not yet been stored";
trajectory.add_object(cup);
ASSERT_TRUE(trajectory.is_object_stored(coke.get_name())) << "Coke was stored";
ASSERT_TRUE(trajectory.is_object_stored(cup.get_name())) << "Cup was stored";
}
// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}