filter_test.cpp
Go to the documentation of this file.
1 
18 #include "gtest/gtest.h"
19 #include "ros/ros.h"
20 #include <boost/shared_ptr.hpp>
22 #include "filter/filter_basic.hpp"
23 
24 using namespace directSearchWS;
25 
26 
27 class MyFilter1 : public FilterBasic {
28 public:
30 
31  MyFilter1(const RobotStatePtrVecPtr &posesToExplorePtr) :
32  FilterBasic(posesToExplorePtr), deleteCount(0) {
33  }
34  virtual ~MyFilter1() { }
35 
36  bool needIteration() {
37  deleteCount = 0;
38  return true;
39  }
40 
42  return true;
43  }
44 
45  bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter) {
46  bool shouldDelete = ptuTuplePtrIter->get()->getDeactivatedObjectNormalsCount() == 1;
47  if (shouldDelete) {
48  ++deleteCount;
49  }
50  return shouldDelete;
51  }
52 };
53 
55 
56 class MyFilter2 : public FilterBasic {
57 public:
59 
60  MyFilter2(const RobotStatePtrVecPtr &posesToExplorePtr) :
61  FilterBasic(posesToExplorePtr), deleteCount(0) {
62  }
63  virtual ~MyFilter2() { }
64 
65  bool needIteration() {
66  deleteCount = 0;
67  return true;
68  }
69 
71  return true;
72  }
73 
74  bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter) {
75  bool shouldDelete = ptuTuplePtrIter->get()->getDeactivatedObjectNormalsCount() >= 1;
76  if (shouldDelete) {
77  ++deleteCount;
78  }
79  return shouldDelete;
80  }
81 };
82 
84 
85 class MyFilter3 : public FilterBasic {
86 public:
88 
89  MyFilter3(const RobotStatePtrVecPtr &posesToExplorePtr) :
90  FilterBasic(posesToExplorePtr), deleteCount(0) {
91  }
92  virtual ~MyFilter3() { }
93 
94  bool needIteration() {
95  deleteCount = 0;
96  return false;
97  }
98 
100  return true;
101  }
102 
103  bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter) {
104  ++deleteCount;
105  return true;
106  }
107 };
108 
110 
113 
115  ptuTuples1->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 1)));
116  ptuTuples1->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 1)));
117  robotStates->push_back(RobotStatePtr(new RobotState(nullptr, ptuTuples1)));
118 
120  ptuTuples2->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 0)));
121  ptuTuples2->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 2)));
122  ptuTuples2->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 0)));
123  ptuTuples2->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 1)));
124  robotStates->push_back(RobotStatePtr(new RobotState(nullptr, ptuTuples2)));
125 
127  ptuTuples3->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 1)));
128  ptuTuples3->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 2)));
129  ptuTuples3->push_back(PtuTuplePtr(new PtuTuple(0, 0, nullptr, 1)));
130  robotStates->push_back(RobotStatePtr(new RobotState(nullptr, ptuTuples3)));
131 
132  return robotStates;
133 }
134 
135 
136 TEST(DoFilterIterationTest, NoFilter) {
137  RobotStatePtrVecPtr robotStates = getRobotStates();
138  DoFilterIteration filterIteration(robotStates);
139 
140  EXPECT_TRUE(filterIteration.doIteration());
141  ASSERT_EQ(3, robotStates->size());
142  for (int robotCount = 0; robotCount < robotStates->size(); ++robotCount) {
143  RobotStatePtr &robotStatePtr = (*robotStates)[robotCount];
144  if (robotCount == 0) {
145  ASSERT_EQ(2, robotStatePtr->getPtuListSize());
146  } else if (robotCount == 1) {
147  ASSERT_EQ(4, robotStatePtr->getPtuListSize());
148  } else {
149  ASSERT_EQ(3, robotStatePtr->getPtuListSize());
150  }
151  for (int ptuCount = 0; ptuCount < robotStatePtr->getPtuListSize(); ++ptuCount) {
152  PtuTuplePtr &ptuTuplePtr = (*robotStatePtr->getPtuTuplePtrVecPtr())[ptuCount];
153  if (robotCount == 0) {
154  EXPECT_EQ(1, ptuTuplePtr->getDeactivatedObjectNormalsCount());
155  } else if (robotCount == 1) {
156  if (ptuCount == 0 || ptuCount == 2) {
157  EXPECT_EQ(0, ptuTuplePtr->getDeactivatedObjectNormalsCount());
158  } else if (ptuCount == 1) {
159  EXPECT_EQ(2, ptuTuplePtr->getDeactivatedObjectNormalsCount());
160  } else {
161  EXPECT_EQ(1, ptuTuplePtr->getDeactivatedObjectNormalsCount());
162  }
163  } else {
164  if (ptuCount == 0 || ptuCount == 2) {
165  EXPECT_EQ(1, ptuTuplePtr->getDeactivatedObjectNormalsCount());
166  } else {
167  EXPECT_EQ(2, ptuTuplePtr->getDeactivatedObjectNormalsCount());
168  }
169  }
170  }
171  }
172 }
173 
174 TEST(DoFilterIterationTest, OneFilter) {
175  RobotStatePtrVecPtr robotStates = getRobotStates();
176  DoFilterIteration filterIteration(robotStates);
177 
178  MyFilter1Ptr filter1 = MyFilter1Ptr(new MyFilter1(robotStates));
179  filterIteration.addFilter(filter1);
180 
181  EXPECT_TRUE(filterIteration.doIteration());
182  ASSERT_EQ(2, robotStates->size());
183  EXPECT_EQ(5, filter1->deleteCount);
184 
185  for (int robotCount = 0; robotCount < robotStates->size(); ++robotCount) {
186  RobotStatePtr &robotStatePtr = (*robotStates)[robotCount];
187  if (robotCount == 0) {
188  ASSERT_EQ(3, robotStatePtr->getPtuListSize());
189  } else {
190  ASSERT_EQ(1, robotStatePtr->getPtuListSize());
191  }
192  for (int ptuCount = 0; ptuCount < robotStatePtr->getPtuListSize(); ++ptuCount) {
193  PtuTuplePtr &ptuTuplePtr = (*robotStatePtr->getPtuTuplePtrVecPtr())[ptuCount];
194  if (robotCount == 0) {
195  if (ptuCount == 0 || ptuCount == 2) {
196  EXPECT_EQ(0, ptuTuplePtr->getDeactivatedObjectNormalsCount());
197  } else {
198  EXPECT_EQ(2, ptuTuplePtr->getDeactivatedObjectNormalsCount());
199  }
200  } else {
201  EXPECT_EQ(2, ptuTuplePtr->getDeactivatedObjectNormalsCount());
202  }
203  }
204  }
205 }
206 
207 TEST(DoFilterIterationTest, MultipleFilters) {
208  RobotStatePtrVecPtr robotStates = getRobotStates();
209  DoFilterIteration filterIteration(robotStates);
210 
211  MyFilter1Ptr filter1 = MyFilter1Ptr(new MyFilter1(robotStates));
212  filterIteration.addFilter(filter1);
213  MyFilter2Ptr filter2 = MyFilter2Ptr(new MyFilter2(robotStates));
214  filterIteration.addFilter(filter2);
215 
216  EXPECT_TRUE(filterIteration.doIteration());
217  ASSERT_EQ(1, robotStates->size());
218  EXPECT_EQ(5, filter1->deleteCount);
219  EXPECT_EQ(2, filter2->deleteCount);
220 
221  RobotStatePtr &robotStatePtr = (*robotStates)[0];
222  ASSERT_EQ(2, robotStatePtr->getPtuListSize());
223  for (int ptuCount = 0; ptuCount < robotStatePtr->getPtuListSize(); ++ptuCount) {
224  PtuTuplePtr &ptuTuplePtr = (*robotStatePtr->getPtuTuplePtrVecPtr())[ptuCount];
225  EXPECT_EQ(0, ptuTuplePtr->getDeactivatedObjectNormalsCount());
226  }
227 
228 
229  robotStates = getRobotStates();
230  MyFilter3Ptr filter3 = MyFilter3Ptr(new MyFilter3(robotStates));
231  filterIteration.addFilter(filter3);
232 
233  EXPECT_TRUE(filterIteration.doIteration());
234  ASSERT_EQ(1, robotStates->size());
235  EXPECT_EQ(5, filter1->deleteCount);
236  EXPECT_EQ(2, filter2->deleteCount);
237  EXPECT_EQ(0, filter3->deleteCount);
238 
239  robotStatePtr = (*robotStates)[0];
240  ASSERT_EQ(2, robotStatePtr->getPtuListSize());
241  for (int ptuCount = 0; ptuCount < robotStatePtr->getPtuListSize(); ++ptuCount) {
242  PtuTuplePtr &ptuTuplePtr = (*robotStatePtr->getPtuTuplePtrVecPtr())[ptuCount];
243  EXPECT_EQ(0, ptuTuplePtr->getDeactivatedObjectNormalsCount());
244  }
245 }
246 
247 TEST(DoFilterIterationTest, NoPoses) {
249  DoFilterIteration filterIteration(robotStates);
250 
251  MyFilter1Ptr filter1 = MyFilter1Ptr(new MyFilter1(robotStates));
252  filterIteration.addFilter(filter1);
253  MyFilter2Ptr filter2 = MyFilter2Ptr(new MyFilter2(robotStates));
254  filterIteration.addFilter(filter2);
255 
256  EXPECT_TRUE(filterIteration.doIteration());
257  ASSERT_EQ(0, robotStates->size());
258  EXPECT_EQ(0, filter1->deleteCount);
259  EXPECT_EQ(0, filter2->deleteCount);
260 }
261 
262 
263 
264 
265 
266 
bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter)
MyFilter1(const RobotStatePtrVecPtr &posesToExplorePtr)
Definition: filter_test.cpp:31
MyFilter3(const RobotStatePtrVecPtr &posesToExplorePtr)
Definition: filter_test.cpp:89
MyFilter2(const RobotStatePtrVecPtr &posesToExplorePtr)
Definition: filter_test.cpp:60
boost::shared_ptr< RobotStatePtrVec > RobotStatePtrVecPtr
Definition: robot_state.hpp:52
void addFilter(const FilterBasicPtr &filter)
bool needIteration()
Definition: filter_test.cpp:36
boost::shared_ptr< MyFilter2 > MyFilter2Ptr
Definition: filter_test.cpp:83
TEST(DoFilterIterationTest, NoFilter)
boost::shared_ptr< PtuTuple > PtuTuplePtr
Definition: ptu_tuple.hpp:69
bool needIteration()
Definition: filter_test.cpp:94
std::vector< PtuTuplePtr > PtuTuplePtrVec
Definition: ptu_tuple.hpp:70
virtual ~MyFilter3()
Definition: filter_test.cpp:92
bool needIteration()
Definition: filter_test.cpp:65
bool wasIterationSuccessful()
Definition: filter_test.cpp:70
bool wasIterationSuccessful()
Definition: filter_test.cpp:99
virtual ~MyFilter2()
Definition: filter_test.cpp:63
RobotStatePtrVecPtr getRobotStates()
bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter)
Definition: filter_test.cpp:74
std::vector< RobotStatePtr > RobotStatePtrVec
Definition: robot_state.hpp:51
boost::shared_ptr< MyFilter3 > MyFilter3Ptr
int deleteCount
Definition: filter_test.cpp:58
int deleteCount
Definition: filter_test.cpp:87
boost::shared_ptr< PtuTuplePtrVec > PtuTuplePtrVecPtr
Definition: ptu_tuple.hpp:71
bool shouldPtuTupleBeDeleted(const RobotStatePtrVec::iterator &posesToExploreIter, const PtuTuplePtrVec::iterator &ptuTuplePtrIter)
Definition: filter_test.cpp:45
boost::shared_ptr< RobotState > RobotStatePtr
Definition: robot_state.hpp:50
bool wasIterationSuccessful()
Definition: filter_test.cpp:41
boost::shared_ptr< MyFilter1 > MyFilter1Ptr
Definition: filter_test.cpp:54
int deleteCount
Definition: filter_test.cpp:29
virtual ~MyFilter1()
Definition: filter_test.cpp:34


asr_direct_search_manager
Author(s): Borella Jocelyn, Karrenbauer Oliver, Mei├čner Pascal
autogenerated on Wed Jan 8 2020 03:15:41