-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestsForAllIndexes.hpp
226 lines (155 loc) · 6.2 KB
/
TestsForAllIndexes.hpp
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
226
#ifndef GEOINDEX_TESTS_FOR_ALL_INDEXES
#define GEOINDEX_TESTS_FOR_ALL_INDEXES
#include "gtest/gtest.h"
#include "Common.hpp"
#include "DomainAssertions.hpp"
namespace geoIndex {
/** All the indexes must pass the tests defined in this file.
* There is no point in duplicating them. Those are the "invariants" that all indexes must respect.
*
* Simply pass each implementation as a parameter and then re-use for the specific tests.
*
* Red mesh: in the original problem statemet we had two meshes. The one to search into was "red".
*/
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_samePoint(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index referenceIndex = 1;
redMesh.index(referencePoint, referenceIndex);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 0.01, result);
ASSERT_INDEX_PRESENT(result, referenceIndex);
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_coincidentPoints(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
redMesh.index(referencePoint, 1);
redMesh.index(referencePoint, 2);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 0.01, result);
ASSERT_INDEX_PRESENT(result, 1);
ASSERT_INDEX_PRESENT(result, 2);
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_noPoints(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 0.01, result);
ASSERT_TRUE(result.empty());
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_onlyFarPoints(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
const Point far1{100, 0, 0};
const Point far2{154, 5, 0};
const Point far3{100, 0, 256};
redMesh.index(far1, 1);
redMesh.index(far2, 2);
redMesh.index(far3, 3);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 0.01, result);
ASSERT_TRUE(result.empty());
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_inAndOutPoints(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
const Point pIn{99.99, 0, 0};
const Point pOut{101.1, 0, 0};
redMesh.index(pIn, 1);
redMesh.index(pOut, 2);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 101, result);
ASSERT_EQ(1, result.size());
ASSERT_INDEX_PRESENT(result, 1);
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_exactDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
const Point onTheBorder{100, 0, 0};
redMesh.index(onTheBorder, 1);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 100, result);
ASSERT_TRUE(result.empty());
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_outputOrder(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
const Point closest{1, 0, 0};
const Point middle{2, 0, 0};
const Point far{3, 0, 0};
const PointTraits<Point>::index closestIndex = 1;
const PointTraits<Point>::index middleIndex = 2;
const PointTraits<Point>::index farIndex = 3;
redMesh.index(closest, closestIndex);
redMesh.index(far, farIndex);
redMesh.index(middle, middleIndex);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 4, result);
ASSERT_EQ(closestIndex, result.at(0).pointIndex);
ASSERT_EQ(middleIndex, result.at(1).pointIndex);
ASSERT_EQ(farIndex, result.at(2).pointIndex);
}
/* Safety checks.*/
template <typename GEOMETRY_INDEX>
void index_duplicatedIndex(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index sameIndex = 1;
redMesh.index(referencePoint, sameIndex);
redMesh.completed();
ASSERT_ANY_THROW(redMesh.index(referencePoint, sameIndex));
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_negativeDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index index = 1;
redMesh.index(referencePoint, index);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(redMesh.pointsWithinDistance(referencePoint, -1, result););
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_zeroDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index index = 1;
redMesh.index(referencePoint, index);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(redMesh.pointsWithinDistance(referencePoint, 0, result););
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_NanDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index index = 1;
redMesh.index(referencePoint, index);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(redMesh.pointsWithinDistance(referencePoint, std::numeric_limits<double>::quiet_NaN(), result););
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_overflowDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{1, 55, 2};
const PointTraits<Point>::index index = 1;
redMesh.index(referencePoint, index);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(redMesh.pointsWithinDistance(referencePoint, std::numeric_limits<double>::max(), result););
}
template <typename GEOMETRY_INDEX>
void pointsWithinDistance_squareDistance(GEOMETRY_INDEX& redMesh) {
const Point referencePoint{0, 0, 0};
const Point neighbor{2, 0, 0};
const PointTraits<Point>::index neighborIndex = 1;
redMesh.index(neighbor, neighborIndex);
redMesh.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
redMesh.pointsWithinDistance(referencePoint, 4, result);
ASSERT_EQ(4, result.at(0).geometricValue);
}
}
#endif