area_occupancy_estimator_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include "../../../src/core/maps/area_occupancy_estimator.h"
4 
5 //--------- Subsuits ---------------------//
6 // === Empty cell, various directions
7 // === Beam stops inside a cell
8 // === Out of cell cases
9 // === Cell touches
10 // === Edge touches
11 // === A beam is collinear to an edge
12 // === A diagonal beam stops at a vertex
13 // === Beam starts from a target cell
14 // === Robot is on an edge
15 //----------------------------------------//
16 
17 class AreaOccupancyEstimatorTest : public ::testing::Test {
18 protected: //consts
19  static constexpr double Base_Empty_Prob = 0.01;
20  static constexpr double Base_Occup_Prob = 0.95;
21  static constexpr double Low_Est_Qual = 0.02;
22  static constexpr double Unknown_Est_Qual = 0.7;
23 protected: // methods
26  Low_Est_Qual, Unknown_Est_Qual}
27  , cell{-1, 1, -1, 1} {}
28 protected: // fields
31 };
32 
33 //----------------------------------------//
34 // === Empty cell, various directions === //
35 
36 TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizPierces) {
37  auto beam = Segment2D{{-50, 0}, {50, 0}};
38  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
39  aoe.estimate_occupancy(beam, cell, false));
40 }
41 
42 TEST_F(AreaOccupancyEstimatorTest, emptyBwdHorizPierces) {
43  auto beam = Segment2D{{50, 0}, {-50, 0}};
44  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
45  aoe.estimate_occupancy(beam, cell, false));
46 }
47 
48 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVerticPierces) {
49  auto beam = Segment2D{{0, -50}, {0, 50}};
50  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
51  aoe.estimate_occupancy(beam, cell, false));
52 }
53 
54 TEST_F(AreaOccupancyEstimatorTest, emptyBwdVerticPierces) {
55  auto beam = Segment2D{{0, 50}, {0, -50}};
56  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
57  aoe.estimate_occupancy(beam, cell, false));
58 }
59 
60 TEST_F(AreaOccupancyEstimatorTest, emptyDlurDiagPierces) {
61  auto beam = Segment2D{{-2, -2}, {2, 2}};
62  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
63  aoe.estimate_occupancy(beam, cell, false));
64 }
65 
66 TEST_F(AreaOccupancyEstimatorTest, emptyFwdDiagPiercesNearBrVertex) {
67  auto beam = Segment2D{{-0.5, 1.5}, {1.5, -0.5}};
68  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.125),
69  aoe.estimate_occupancy(beam, cell, false));
70 }
71 
72 TEST_F(AreaOccupancyEstimatorTest, emptyFwdPiercesBlVertexRight) {
73  auto beam = Segment2D{{-3, -2}, {3, 1}};
74  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.25),
75  aoe.estimate_occupancy(beam, cell, false));
76 }
77 
78 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVerticPiercesNearCellBorder) {
79  auto beam = Segment2D{{0.9, -2}, {0.9, 2}};
80  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.05),
81  aoe.estimate_occupancy(beam, cell, false));
82 }
83 
84 //----------------------------------//
85 // === Beam stops inside a cell === //
86 
87 TEST_F(AreaOccupancyEstimatorTest, occFwdHorizStopsCenter) {
88  auto beam = Segment2D{{-50, 0}, {0, 0}};
89  ASSERT_EQ(Occupancy(0.5, 1.0),
90  aoe.estimate_occupancy(beam, cell, true));
91 }
92 
93 TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizStopsCenter) {
94  // Clarify
95  auto beam = Segment2D{{-50, 0}, {0, 0}};
97  aoe.estimate_occupancy(beam, cell, false));
98 }
99 
100 TEST_F(AreaOccupancyEstimatorTest, occFwdHorizNotReachingCenter) {
101  auto beam = Segment2D{{-50, 0}, {0.5, 0}};
102  ASSERT_EQ(Occupancy(0.25, 1),
103  aoe.estimate_occupancy(beam, cell, true));
104 }
105 
106 TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizNotReachingCenter) {
107  auto beam = Segment2D{{-50, 0}, {0.5, 0}};
109  aoe.estimate_occupancy(beam, cell, false));
110 }
111 
112 TEST_F(AreaOccupancyEstimatorTest, occBwdHorizNotReachingCenter) {
113  auto beam = Segment2D{{50, 0}, {0.5, 0}};
114  ASSERT_EQ(Occupancy(0.75, 1),
115  aoe.estimate_occupancy(beam, cell, true));
116 }
117 
118 TEST_F(AreaOccupancyEstimatorTest, emptyBwdHorizNotReachingCenter) {
119  auto beam = Segment2D{{50, 0}, {0.5, 0}};
121  aoe.estimate_occupancy(beam, cell, false));
122 }
123 
124 TEST_F(AreaOccupancyEstimatorTest, occFwdDiagNotReachingCenter) {
125  auto beam = Segment2D{{-50, -50}, {0.5, 0.5}};
126  ASSERT_EQ(Occupancy(0.125, 1),
127  aoe.estimate_occupancy(beam, cell, true));
128 }
129 
130 TEST_F(AreaOccupancyEstimatorTest, emptyFwdDiagNotReachingCenter) {
131  auto beam = Segment2D{{-50, -50}, {0.5, 0.5}};
133  aoe.estimate_occupancy(beam, cell, false));
134 }
135 
136 TEST_F(AreaOccupancyEstimatorTest, occBwdDiagNotReachingCenter) {
137  auto beam = Segment2D{{50, 50}, {0.5, 0.5}};
138  ASSERT_EQ(Occupancy(0.875, 1),
139  aoe.estimate_occupancy(beam, cell, true));
140 }
141 
142 TEST_F(AreaOccupancyEstimatorTest, occBwdSkewDiagStopsCenter) {
143  auto beam = Segment2D{{-2, 4}, {0, 0}};
144  ASSERT_EQ(Occupancy(0.5, 1),
145  aoe.estimate_occupancy(beam, cell, true));
146 }
147 
148 TEST_F(AreaOccupancyEstimatorTest, emptyBwdSkewDialStopsCenter) {
149  auto beam = Segment2D{{-2, 4}, {0, 0}};
151  aoe.estimate_occupancy(beam, cell, false));
152 }
153 
154 //---------------------------//
155 // === Out of cell cases === //
156 
157 TEST_F(AreaOccupancyEstimatorTest, occNotInteractsWithCell) {
158  auto beam = Segment2D{{2, 2}, {3, 3}};
159  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
160 }
161 
162 TEST_F(AreaOccupancyEstimatorTest, emptySkewDiagotCrossCell) {
163  auto beam = Segment2D{{0, 50}, {-2, 0}};
164  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
165 }
166 
167 //----------------------//
168 // === Cell touches === //
169 
170 TEST_F(AreaOccupancyEstimatorTest, occTouchesLeftTopVertex) {
171  auto beam = Segment2D{{-2, 0}, {0, 2}};
172  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
173 }
174 
175 TEST_F(AreaOccupancyEstimatorTest, emptyTouchesLeftTopVertex) {
176  auto beam = Segment2D{{-2, 0}, {0, 2}};
177  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
178 }
179 
180 TEST_F(AreaOccupancyEstimatorTest, occTouchesLeftBotVertex) {
181  auto beam = Segment2D{{-2, 0}, {0, -2}};
182  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
183 }
184 
185 TEST_F(AreaOccupancyEstimatorTest, emptyTouchesLeftBotVertex) {
186  auto beam = Segment2D{{-2, 0}, {0, -2}};
187  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
188 }
189 
190 TEST_F(AreaOccupancyEstimatorTest, occTouchesRightBotVertex) {
191  auto beam = Segment2D{{2, 0}, {0, -2}};
192  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
193 }
194 
195 TEST_F(AreaOccupancyEstimatorTest, emptyTouchesRightBotVertex) {
196  auto beam = Segment2D{{2, 0}, {0, -2}};
197  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
198 }
199 
200 TEST_F(AreaOccupancyEstimatorTest, occTouchesRightTopVertex) {
201  auto beam = Segment2D{{2, 0}, {0, 2}};
202  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));;
203 }
204 
205 TEST_F(AreaOccupancyEstimatorTest, emptyTouchesRightTopVertex) {
206  auto beam = Segment2D{{2, 0}, {0, 2}};
207  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
208 }
209 
210 //----------------------//
211 // === Edge touches === //
212 
213 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVerticStopsRearEdgeThroughCenter) {
214  auto beam = Segment2D{{0, -4}, {0, 1}};
215  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
216  aoe.estimate_occupancy(beam, cell, false));
217 }
218 
219 TEST_F(AreaOccupancyEstimatorTest, occFwdVerticStopsRearEdgeThroughCenter) {
220  auto beam = Segment2D{{0, -4}, {0, 1}};
221  ASSERT_EQ(Occupancy(Base_Empty_Prob, 1.0),
222  aoe.estimate_occupancy(beam, cell, true));
223 }
224 
225 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVerticStopsFrontEdge) {
226  auto beam = Segment2D{{0, -4}, {0, -1}};
228  aoe.estimate_occupancy(beam, cell, false));
229 }
230 
231 TEST_F(AreaOccupancyEstimatorTest, occFwdVerticStopsFrontEdge) {
232  auto beam = Segment2D{{0, -4}, {0, -1}};
233  ASSERT_EQ(Occupancy(1, 1), aoe.estimate_occupancy(beam, cell, true));
234 }
235 
236 
237 TEST_F(AreaOccupancyEstimatorTest, occBwdVerticStopsFrontEdge) {
238  auto beam = Segment2D{{0, 4}, {0, 1}};
239  ASSERT_EQ(Occupancy(1, 1), aoe.estimate_occupancy(beam, cell, true));
240 }
241 
242 TEST_F(AreaOccupancyEstimatorTest, emptyBwdVerticStopsFrontEdge) {
243  // Clarify: Empty_UD_SideAligned_NotReachingCenter
244  auto beam = Segment2D{{0, 4}, {0, 1}};
246  aoe.estimate_occupancy(beam, cell, false));
247 }
248 
249 TEST_F(AreaOccupancyEstimatorTest, emptyBwdVerticStopsRearEdge) {
250  auto beam = Segment2D{{0, 4}, {0, -1}};
251  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
252  aoe.estimate_occupancy(beam, cell, false));
253 }
254 
255 TEST_F(AreaOccupancyEstimatorTest, occBwdVerticStopsRearEdge) {
256  // Clarify
257  auto beam = Segment2D{{0, 4}, {0, -1}};
258  ASSERT_EQ(Occupancy(Base_Empty_Prob, 1.0),
259  aoe.estimate_occupancy(beam, cell, true));
260 }
261 
262 TEST_F(AreaOccupancyEstimatorTest, emptyBwdHorizStopsRearEdge) {
263  auto beam = Segment2D{{4, 0}, {-1, 0}};
264  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
265  aoe.estimate_occupancy(beam, cell, false));
266 }
267 
268 TEST_F(AreaOccupancyEstimatorTest, occBwdHorizStopsRearEdge) {
269  auto beam = Segment2D{{4, 0}, {-1, 0}};
270  ASSERT_EQ(Occupancy(Base_Empty_Prob, 1.0),
271  aoe.estimate_occupancy(beam, cell, true));
272 }
273 
274 TEST_F(AreaOccupancyEstimatorTest, occBwdHorizStopsFrontEdge) {
275  auto beam = Segment2D{{4, 0}, {1, 0}};
276  ASSERT_EQ(Occupancy(1, 1), aoe.estimate_occupancy(beam, cell, true));
277 }
278 
279 TEST_F(AreaOccupancyEstimatorTest, emptyBwhHorizStopsFrontEdge) {
280  auto beam = Segment2D{{4, 0}, {1, 0}};
282  aoe.estimate_occupancy(beam, cell, false));
283 }
284 
285 TEST_F(AreaOccupancyEstimatorTest, occFwdHorizStopsFrontEdge) {
286  auto beam = Segment2D{{-4, 0}, {-1, 0}};
287  ASSERT_EQ(Occupancy(1, 1), aoe.estimate_occupancy(beam, cell, true));
288 }
289 
290 TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizStopsFrontEdge) {
291  auto beam = Segment2D{{-4, 0}, {-1, 0}};
293  aoe.estimate_occupancy(beam, cell, false));
294 }
295 
296 TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizStopsRearEdge) {
297  auto beam = Segment2D{{-4, 0}, {1, 0}};
298  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
299  aoe.estimate_occupancy(beam, cell, false));
300 }
301 
302 TEST_F(AreaOccupancyEstimatorTest, occFwdHorizStopsRearEdge) {
303  auto beam = Segment2D{{-4, 0}, {1, 0}};
304  ASSERT_EQ(Occupancy(Base_Empty_Prob, 1.0),
305  aoe.estimate_occupancy(beam, cell, true));
306 }
307 
308 //----------------------------------------//
309 // === A beam is collinear to an edge === //
310 
311 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVertLiesOnEdge) {
312  // Clarify: Empty_DU_PassesSide
313  auto beam = Segment2D{{-1, -2}, {-1, 2}};
315  aoe.estimate_occupancy(beam, cell, false));
316 }
317 
318 TEST_F(AreaOccupancyEstimatorTest, occFwdVertLiesOnEdge) {
319  auto beam = Segment2D{{-1, -2}, {-1, 2}};
320  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
321 }
322 
323 TEST_F(AreaOccupancyEstimatorTest, occFwdVertStopsOnEdge) {
324  // Clarify
325  auto beam = Segment2D{{-1, -2}, {-1, 0}};
326  ASSERT_EQ(Occupancy(0.5, 1),
327  aoe.estimate_occupancy(beam, cell, true));
328 }
329 
330 TEST_F(AreaOccupancyEstimatorTest, emptyFwdVertStopsOnEdge) {
331  // Clarify: ??
332  auto beam = Segment2D{{-1, -2}, {-1, 0}};
334  aoe.estimate_occupancy(beam, cell, false));
335 }
336 
337 //-------------------------------------------//
338 // === A diagonal beam stops at a vertex === //
339 
340 TEST_F(AreaOccupancyEstimatorTest, occDuDiagAlignedStopsAtFrontVertex) {
341  auto beam = Segment2D{{2, -2}, {1, -1}};
342  ASSERT_EQ(Occupancy(1, 1), aoe.estimate_occupancy(beam, cell, true));
343 }
344 
345 
346 TEST_F(AreaOccupancyEstimatorTest, emptyDuDiagAlignedStopsAtFrontVertex) {
347  auto beam = Segment2D{{2, -2}, {1, -1}};
349  aoe.estimate_occupancy(beam, cell, false));
350 }
351 
352 TEST_F(AreaOccupancyEstimatorTest, emptyDuDiagAlignedStopsAtRearVertex) {
353  auto beam = Segment2D{{2, -2}, {-1, 1}};
354  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
355  aoe.estimate_occupancy(beam, cell, false));
356 }
357 
358 TEST_F(AreaOccupancyEstimatorTest, occDuDiagAlignedStopsAtRearVertex) {
359  auto beam = Segment2D{{2, -2}, {-1, 1}};
360  ASSERT_EQ(Occupancy(Base_Empty_Prob, 0.5),
361  aoe.estimate_occupancy(beam, cell, true));
362 }
363 
364 //----------------------------------------//
365 // === Beam starts from a target cell === //
366 
367 TEST_F(AreaOccupancyEstimatorTest, emptyInsideStopsOut) {
368  auto beam = Segment2D{{-0.5, -0.5}, {0, 50}};
370  aoe.estimate_occupancy(beam, cell, false));
371 }
372 
373 TEST_F(AreaOccupancyEstimatorTest, occInsideStopsOut) {
374  auto beam = Segment2D{{-0.5, -0.5}, {0, 50}};
375  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
376 }
377 
378 TEST_F(AreaOccupancyEstimatorTest, emptyInsideStopsBorder) {
379  auto beam = Segment2D{{-0.5, -0.5}, {1, 1}};
381  aoe.estimate_occupancy(beam, cell, false));
382 }
383 
384 TEST_F(AreaOccupancyEstimatorTest, occInsideStopsBorder) {
385  auto beam = Segment2D{{-0.5, -0.5}, {1, 1}};
386  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
387 }
388 
389 TEST_F(AreaOccupancyEstimatorTest, occInsideStopsCenter) {
390  auto beam = Segment2D{{-0.5, -0.5}, {0, 0}};
391  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
392 }
393 
394 TEST_F(AreaOccupancyEstimatorTest, emptyInsideStopsCenter) {
395  auto beam = Segment2D{{-0.5, -0.5}, {0, 0}};
397  aoe.estimate_occupancy(beam, cell, false));
398 }
399 
401  auto beam = Segment2D{{0.5, 0.5}, {0.5, 0.5}};
403  aoe.estimate_occupancy(beam, cell, false));
404 }
405 
406 //-----------------------------//
407 // === Robot is on an edge === //
408 
410  auto beam = Segment2D{{0, 1}, {1, -2}};
411  ASSERT_EQ(Occupancy(Base_Empty_Prob, 1.0 / 3.0),
412  aoe.estimate_occupancy(beam, cell, false));
413 }
414 
416  auto beam = Segment2D{{0, 1}, {1, -2}};
417  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
418 }
419 
420 TEST_F(AreaOccupancyEstimatorTest, occOnEdgeOutNotThrouhCell) {
421  auto beam = Segment2D{{0, 1}, {2, 2}};
422  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, true));
423 }
424 
425 TEST_F(AreaOccupancyEstimatorTest, emptyOnEdgeOutNotThrouhCell) {
426  auto beam = Segment2D{{0, 1}, {2, 2}};
427  ASSERT_EQ(Occupancy::invalid(), aoe.estimate_occupancy(beam, cell, false));
428 }
429 
430 int main (int argc, char *argv[]) {
431  ::testing::InitGoogleTest(&argc, argv);
432  return RUN_ALL_TESTS();
433 }
static Occupancy invalid()
Definition: state_data.h:27
TEST_F(AreaOccupancyEstimatorTest, emptyFwdHorizPierces)
int main(int argc, char *argv[])
Occupancy estimate_occupancy(const Segment2D &beam, const Rectangle &cell, bool is_occ) override


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25