costmap_tools_tests.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
4 #include "boost/foreach.hpp"
5 
6 #include <gtest/gtest.h>
7 
8 
9 class NeighborhoodFunctionTest : public ::testing::Test{
10 protected:
11  virtual void SetUp(){
12  //create map of 10 x 10
13  costmap_.resizeMap(9,9,0.1,0,0);
14  }
16 };
17 
19 {
20 
21  unsigned int idx = costmap_.getIndex(4,4);
22  ASSERT_EQ(4,frontier_exploration::nhood4(idx,costmap_).size());
23  ASSERT_EQ(8,frontier_exploration::nhood8(idx,costmap_).size());
24 
25 }
26 
28 {
29 
30  std::list<unsigned int> to_test;
31  to_test.push_back(costmap_.getIndex(4,8));
32  to_test.push_back(costmap_.getIndex(4,0));
33  to_test.push_back(costmap_.getIndex(8,4));
34  to_test.push_back(costmap_.getIndex(0,4));
35  BOOST_FOREACH(unsigned int idx, to_test){
36  ASSERT_EQ(3,frontier_exploration::nhood4(idx,costmap_).size());
37  ASSERT_EQ(5,frontier_exploration::nhood8(idx,costmap_).size());
38  }
39 }
40 
41 
43 {
44 
45  std::list<unsigned int> to_test;
46  to_test.push_back(costmap_.getIndex(8,8));
47  to_test.push_back(costmap_.getIndex(8,0));
48  to_test.push_back(costmap_.getIndex(8,0));
49  to_test.push_back(costmap_.getIndex(0,0));
50  BOOST_FOREACH(unsigned int idx, to_test){
51  ASSERT_EQ(2,frontier_exploration::nhood4(idx,costmap_).size());
52  ASSERT_EQ(3,frontier_exploration::nhood8(idx,costmap_).size());
53  }
54 
55 }
56 
58 {
59 
60  unsigned int idx = costmap_.getIndex(12,12);
61  ASSERT_EQ(0,frontier_exploration::nhood4(idx,costmap_).size());
62  ASSERT_EQ(0,frontier_exploration::nhood8(idx,costmap_).size());
63 
64 }
65 
66 class NearestCellTest : public ::testing::Test{
67 protected:
68  virtual void SetUp(){
69  //create map of 10 x 10
70  costmap_.resizeMap(9,9,0.1,0,0);
71  unsigned char* map = costmap_.getCharMap();
72  const unsigned int size_x = costmap_.getSizeInCellsX(), size_y = costmap_.getSizeInCellsY();
73 
74  std::fill(map, map+ (size_x*size_y)/2, 0);
75  std::fill(map+(size_x*size_y)/2 + 1, map+(size_x*size_y), 1);
76  }
77 
79 };
80 
82 {
83  unsigned int input = 80;
84  unsigned int result;
85  ASSERT_TRUE(frontier_exploration::nearestCell(result,input,1,costmap_));
86  ASSERT_EQ(input,result);
87 
88 }
89 
90 TEST_F(NearestCellTest, differentCell)
91 {
92  unsigned int input = 20;
93  unsigned int result;
94  ASSERT_TRUE(frontier_exploration::nearestCell(result,input,1,costmap_));
95  ASSERT_NE(input,result);
96 
97 }
98 
100 {
101  unsigned int input = std::numeric_limits<unsigned int>::max();
102  unsigned int result;
103  ASSERT_FALSE(frontier_exploration::nearestCell(result,input,1,costmap_));
104 
105 }
106 
107 int main(int argc, char **argv){
108  testing::InitGoogleTest(&argc, argv);
109  return RUN_ALL_TESTS();
110 }
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y)
std::vector< unsigned int > nhood4(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 4-connected neighbourhood of an input cell, checking for map edges.
Definition: costmap_tools.h:18
int main(int argc, char **argv)
TEST_F(NeighborhoodFunctionTest, middle)
bool nearestCell(unsigned int &result, unsigned int start, unsigned char val, const costmap_2d::Costmap2D &costmap)
Find nearest cell of a specified value.
Definition: costmap_tools.h:86
unsigned char * getCharMap() const
costmap_2d::Costmap2D costmap_
std::vector< unsigned int > nhood8(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 8-connected neighbourhood of an input cell, checking for map edges.
Definition: costmap_tools.h:51
unsigned int getSizeInCellsY() const
unsigned int getSizeInCellsX() const
costmap_2d::Costmap2D costmap_
virtual void SetUp()
unsigned int getIndex(unsigned int mx, unsigned int my) const


frontier_exploration
Author(s): Paul Bovbel
autogenerated on Mon Jun 10 2019 13:25:00