utest.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #include <gtest/gtest.h>
38 #include <ros/ros.h>
39 #include <memory>
40 #include <algorithm>
41 
42 
44 
45 TEST(CostmapQueue, basicQueue)
46 {
47  costmap_queue::CostmapQueue q(costmap);
48  int count = 0;
49  q.enqueueCell(0, 0);
50  while (!q.isEmpty())
51  {
53  EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
54  count++;
55  }
56  EXPECT_EQ(count, 25);
57 }
58 
59 TEST(CostmapQueue, reverseQueue)
60 {
61  costmap_queue::CostmapQueue q(costmap);
62  int count = 0;
63  q.enqueueCell(4, 4);
64  while (!q.isEmpty())
65  {
67  EXPECT_FLOAT_EQ(cell.distance_, hypot(4.0 - static_cast<double>(cell.x_),
68  4.0 - static_cast<double>(cell.y_)));
69  count++;
70  }
71  EXPECT_EQ(count, 25);
72 }
73 
74 TEST(CostmapQueue, bigTest)
75 {
76  nav_grid::NavGridInfo big_info;
77  big_info.width = 500;
78  big_info.height = 500;
79 
81  big_map.setInfo(big_info);
82  costmap_queue::CostmapQueue q(big_map);
83  int count = 0;
84  q.enqueueCell(0, 0);
85  while (!q.isEmpty())
86  {
88  EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
89  count++;
90  }
91  EXPECT_EQ(count, 500 * 500);
92 }
93 
94 TEST(CostmapQueue, linearQueue)
95 {
96  costmap_queue::CostmapQueue q(costmap);
97  int count = 0;
98  q.enqueueCell(0, 0);
99  q.enqueueCell(0, 1);
100  q.enqueueCell(0, 2);
101  q.enqueueCell(0, 3);
102  q.enqueueCell(0, 4);
103  while (!q.isEmpty())
104  {
106  EXPECT_FLOAT_EQ(cell.distance_, cell.x_);
107  count++;
108  }
109  EXPECT_EQ(count, 25);
110 }
111 
112 TEST(CostmapQueue, crossQueue)
113 {
114  costmap_queue::CostmapQueue q(costmap);
115  int count = 0;
116  int xs[] = {1, 2, 2, 3};
117  int ys[] = {2, 1, 3, 2};
118  int N = 4;
119  for (int i = 0; i < N; i++)
120  {
121  q.enqueueCell(xs[i], ys[i]);
122  }
123 
124  while (!q.isEmpty())
125  {
127  double min_d = 1000;
128 
129  for (int i = 0; i < N; i++)
130  {
131  double dd = hypot(xs[i] - static_cast<float>(cell.x_), ys[i] - static_cast<float>(cell.y_));
132  min_d = std::min(min_d, dd);
133  }
134  EXPECT_FLOAT_EQ(cell.distance_, min_d);
135  count++;
136  }
137  EXPECT_EQ(count, 25);
138 }
139 
140 TEST(CostmapQueue, limitedQueue)
141 {
143  int count = 0;
144  q.enqueueCell(0, 0);
145  while (!q.isEmpty())
146  {
148  EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
149  count++;
150  }
151  EXPECT_EQ(count, 24);
152 
153  costmap_queue::LimitedCostmapQueue q2(costmap, 3);
154  count = 0;
155  q2.enqueueCell(0, 0);
156  while (!q2.isEmpty())
157  {
158  q2.getNextCell();
159  count++;
160  }
161  EXPECT_EQ(count, 11);
162 }
163 
164 
165 TEST(CostmapQueue, changingSize)
166 {
167  nav_grid::NavGridInfo info0;
168  info0.width = 2;
169  info0.height = 3;
170 
171  nav_grid::NavGridInfo info1;
172  info1.width = 6;
173  info1.height = 7;
174 
175  nav_core2::BasicCostmap size_map;
176  size_map.setInfo(info0);
177  costmap_queue::CostmapQueue q(size_map);
178  unsigned int count = 0;
179  q.enqueueCell(0, 0);
180  while (!q.isEmpty())
181  {
182  q.getNextCell();
183  count++;
184  }
185 
186  EXPECT_EQ(count, info0.width * info0.height);
187 
188  size_map.setInfo(info1);
189  q.reset();
190  count = 0;
191  q.enqueueCell(0, 0);
192  while (!q.isEmpty())
193  {
194  q.getNextCell();
195  count++;
196  }
197  EXPECT_EQ(count, info1.width * info1.height);
198 }
199 
200 int main(int argc, char **argv)
201 {
202  testing::InitGoogleTest(&argc, argv);
204  info.width = 5;
205  info.height = 5;
206  costmap.setInfo(info);
207  return RUN_ALL_TESTS();
208 }
void reset() override
Clear the queue.
nav_core2::BasicCostmap costmap
Definition: utest.cpp:43
TEST(CostmapQueue, basicQueue)
Definition: utest.cpp:45
A tool for finding the cells closest to some set of originating cells.
Definition: costmap_queue.h:99
Extension of Costmap Queue where distances are limited to a given distance from source cells...
void enqueueCell(unsigned int x, unsigned int y)
Add a cell the queue.
int main(int argc, char **argv)
Definition: utest.cpp:200
Storage for cell information used during queue expansion.
Definition: costmap_queue.h:51
bool isEmpty()
Check to see if there is anything in the queue.
void setInfo(const nav_grid::NavGridInfo &new_info) override
CellData getNextCell()
Get the next cell to examine, and enqueue its neighbors as needed.


costmap_queue
Author(s):
autogenerated on Wed Jun 26 2019 20:06:08