occupancy_observation_probability_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <memory>
4 #include <limits>
5 
6 #include "../mock_grid_cell.h"
7 #include "../../../src/core/maps/plain_grid_map.h"
8 #include "../../../src/core/scan_matchers/occupancy_observation_probability.h"
9 
10 // FIXME: [Refactoring] single case per method.
11 
12 class BaseOOPETest : public ::testing::Test {
13 public:
14  static constexpr double Map_Scale = 1;
15  static constexpr double Default_Prob = 0.0;
16 public:
18  : map{std::make_shared<MockGridCell>(Default_Prob),
19  {100, 100, Map_Scale}} {
20  update_map({0, 1}, 0.25); update_map({1, 1}, 0.00);
21  update_map({0, 0}, 1.00); update_map({1, 0}, 0.50);
22  }
23 protected:
26  using Shift = Point2D;
27 
28  void update_map(const UnboundedPlainGridMap::Coord &area_id, double occ) {
29  map.update(area_id, AOO{true, {occ, 1}, {0, 0}, 1});
30  }
31 
32  template <typename OOPE>
33  void test_oope(double expected, const Point2D &obstacle,
34  const LWR &range = {0, 0, 0, 0}) const {
35  auto actual = OOPE{}.probability(AOO{true, {1, 1}, obstacle, 1},
36  range.move_center(obstacle), map);
37  ASSERT_NEAR(expected, actual, std::numeric_limits<double>::epsilon());
38  }
39 
40  auto cell_range() const { return LWR{0, Map_Scale, 0, Map_Scale}; }
41  auto mid_cell() const { return Shift{Map_Scale / 2, Map_Scale / 2}; }
42 
43  template <int i, int j>
44  auto mid() const { return mid_cell() + Shift{i * Map_Scale, j * Map_Scale}; }
45 protected:
47 };
48 
49 /******************************************************************************/
50 // == ObstacleBasedOOPE tests
51 
53 protected:
55 };
56 
58  test_oope<OOPE>(1, mid<0,0>());
59 }
60 
61 TEST_F(ObstacleBasedOOPETest, areaNeutrality) {
62  test_oope<OOPE>(1, mid<0,0>(), {-1000, 1000, -1000, 1000});
63 }
64 
65 TEST_F(ObstacleBasedOOPETest, shiftInsideCellNeutrality) {
66  test_oope<OOPE>(1, mid<0,0>());
67  test_oope<OOPE>(1, mid<0,0>() + Shift{Map_Scale, Map_Scale} * 0.25);
68 }
69 
70 TEST_F(ObstacleBasedOOPETest, shiftNearCell) {
71  test_oope<OOPE>(1.00, mid<0,0>());
72  test_oope<OOPE>(0.25, mid<0,0>() + Shift{0, Map_Scale});
73  test_oope<OOPE>(0.50, mid<0,0>() + Shift{Map_Scale, 0});
74  test_oope<OOPE>(0.00, mid<0,0>() + Shift{Map_Scale, Map_Scale});
75 }
76 
77 /******************************************************************************/
78 // == MaxOOPE tests
79 
80 class MaxOOPETest : public BaseOOPETest {
81 protected:
83 };
84 
85 TEST_F(MaxOOPETest, obstacleMid) {
86  test_oope<OOPE>(1, mid<0,0>());
87 }
88 
89 TEST_F(MaxOOPETest, shiftInsideCell) {
90  auto range = cell_range().shrink(2);
91  test_oope<OOPE>(0.25, mid<0,1>(), range);
92  test_oope<OOPE>(1, mid<0,1>() + Shift{0, -Map_Scale} * 0.5, range);
93  test_oope<OOPE>(0.25, mid<0,1>() + Shift{Map_Scale, 0} * 0.5, range);
94  test_oope<OOPE>(1, mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.5, range);
95  test_oope<OOPE>(0.5, mid<1,0>() + Shift{0, Map_Scale} * 0.5, range);
96 }
97 
98 TEST_F(MaxOOPETest, severalCellCoverNeutralityToSmallShift) {
99  auto range = cell_range().shrink(2);
100  test_oope<OOPE>(0.25, mid<0,1>(), range);
101  test_oope<OOPE>(1, mid<0,1>() + Shift{0, -Map_Scale} * 0.375, range);
102  test_oope<OOPE>(0.25, mid<0,1>() + Shift{Map_Scale, 0} * 0.375, range);
103  test_oope<OOPE>(1, mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.375, range);
104 }
105 
106 TEST_F(MaxOOPETest, observationAreaScaling) {
107  auto range = cell_range();
108  test_oope<OOPE>(Default_Prob, mid<1, -1>(), range.shrink(2));
109  test_oope<OOPE>(0.5, mid<1, -1>(), range);
110  test_oope<OOPE>(1, mid<1,-1>(), range.shrink(0.5));
111 }
112 
113 /******************************************************************************/
114 // == MeanOOPE tests
115 
116 class MeanOOPETest : public BaseOOPETest {
117 protected:
119 };
120 
121 TEST_F(MeanOOPETest, obstacleMid) {
122  test_oope<OOPE>(1, mid<0,0>());
123 }
124 
125 TEST_F(MeanOOPETest, shiftInsideCell) {
126  auto range = cell_range().shrink(2);
127  test_oope<OOPE>(0.25, mid<0,1>(), range);
128  test_oope<OOPE>(1.25 / 2, mid<0,1>() + Shift{0, -Map_Scale} * 0.5, range);
129  test_oope<OOPE>(0.25 / 2, mid<0,1>() + Shift{Map_Scale, 0} * 0.5, range);
130  test_oope<OOPE>(1.75 / 4,
131  mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.5, range);
132 }
133 
134 TEST_F(MeanOOPETest, severalCellCoverNeutralityToSmallShift) {
135  auto range = cell_range().shrink(2);
136  test_oope<OOPE>(0.25, mid<0,1>(), range);
137  // TODO: cmp with no small shift
138  test_oope<OOPE>(1.25 / 2, mid<0,1>() + Shift{0, -Map_Scale} * 0.375, range);
139  test_oope<OOPE>(0.25 / 2, mid<0,1>() + Shift{Map_Scale, 0} * 0.375, range);
140  test_oope<OOPE>(1.75 / 4,
141  mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.375, range);
142  test_oope<OOPE>(0.5 / 2, mid<1,0>() + Shift{0, Map_Scale} * 0.375, range);
143 }
144 
145 TEST_F(MeanOOPETest, observationAreaScaling) {
146  auto range = cell_range();
147  test_oope<OOPE>(Default_Prob, mid<1, -1>(), range.shrink(2));
148  test_oope<OOPE>(0.5 / 4, mid<1, -1>(), range);
149  test_oope<OOPE>(1.5 / 9, mid<1,-1>(), range.shrink(0.5));
150 }
151 
152 /******************************************************************************/
153 // == OverlapWeghtedOOPE tests
154 
156 protected:
158 };
159 
161  test_oope<OOPE>(1, mid<0,0>());
162 }
163 
164 TEST_F(OverlapWeghtedOOPETest, shiftInsideCell) {
165  auto range = cell_range().shrink(2);
166  test_oope<OOPE>(0.25, mid<0,1>(), range);
167  test_oope<OOPE>(0.625, mid<0,1>() + Shift{0, -Map_Scale} * 0.5, range);
168  test_oope<OOPE>(0.25 / 2, mid<0,1>() + Shift{Map_Scale, 0} * 0.5, range);
169  test_oope<OOPE>(1.75 / 4,
170  mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.5, range);
171  test_oope<OOPE>(0.5 / 2, mid<1,0>() + Shift{0, Map_Scale} * 0.5, range);
172 }
173 
174 TEST_F(OverlapWeghtedOOPETest, severalCellCoverSmallShift) {
175  auto range = cell_range().shrink(2);
176  test_oope<OOPE>(0.25, mid<0,1>(), range);
177  test_oope<OOPE>(0.4375, mid<0,1>() + Shift{0, -Map_Scale} * 0.375, range);
178  test_oope<OOPE>(0.1875, mid<0,1>() + Shift{Map_Scale, 0} * 0.375, range);
179  test_oope<OOPE>(0.25*0.25*0.5 + 0.25 * 0.75 * 1 + 0.75 * 0.75 * 0.25,
180  mid<0,1>() + Shift{Map_Scale, -Map_Scale} * 0.375, range);
181 }
182 
183 TEST_F(OverlapWeghtedOOPETest, observationAreaScaling) {
184  auto range = cell_range();
185  test_oope<OOPE>(0.5*0.25 + 1*0.125 + 0.25*0.0625,
186  mid<1,0>(), range.shrink(0.5));
187 }
188 
189 TEST_F(OverlapWeghtedOOPETest, observationAreaScalingSmalShift) {
190  auto range = cell_range();
191  test_oope<OOPE>((0.5*1 + 1*0.25 + 0.25*0.0625) / 2.25,
192  mid<1,0>(), range.shrink(2.0 / 3.0));
193 }
194 
195 /******************************************************************************/
196 // == OOPEAssumptions tests
197 
199 
200 TEST_F(OOPEAssumptionsTest, pointAreaLeadsToTheSameProbability) {
201  auto point_area = LWR{};
202  test_oope<ObstacleBasedOccupancyObservationPE>(0.5, mid<1,0>(), point_area);
203  test_oope<MaxOccupancyObservationPE>(0.5, mid<1,0>(), point_area);
204  test_oope<MeanOccupancyObservationPE>(0.5, mid<1,0>(), point_area);
205  test_oope<OverlapWeightedOccupancyObservationPE>(0.5, mid<1,0>(), point_area);
206 }
207 
208 /******************************************************************************/
209 
210 int main (int argc, char *argv[]) {
211  ::testing::InitGoogleTest(&argc, argv);
212  return RUN_ALL_TESTS();
213 }
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
TEST_F(ObstacleBasedOOPETest, obstacleMid)
void update_map(const UnboundedPlainGridMap::Coord &area_id, double occ)
int main(int argc, char *argv[])
static constexpr double Default_Prob
void test_oope(double expected, const Point2D &obstacle, const LWR &range={0, 0, 0, 0}) const


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