00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <gtest/gtest.h>
00035 #include <nav_core2/basic_costmap.h>
00036 #include <costmap_queue/costmap_queue.h>
00037 #include <costmap_queue/limited_costmap_queue.h>
00038 #include <ros/ros.h>
00039 #include <memory>
00040 #include <algorithm>
00041
00042
00043 nav_core2::BasicCostmap costmap;
00044
00045 TEST(CostmapQueue, basicQueue)
00046 {
00047 costmap_queue::CostmapQueue q(costmap);
00048 int count = 0;
00049 q.enqueueCell(0, 0);
00050 while (!q.isEmpty())
00051 {
00052 costmap_queue::CellData cell = q.getNextCell();
00053 EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
00054 count++;
00055 }
00056 EXPECT_EQ(count, 25);
00057 }
00058
00059 TEST(CostmapQueue, reverseQueue)
00060 {
00061 costmap_queue::CostmapQueue q(costmap);
00062 int count = 0;
00063 q.enqueueCell(4, 4);
00064 while (!q.isEmpty())
00065 {
00066 costmap_queue::CellData cell = q.getNextCell();
00067 EXPECT_FLOAT_EQ(cell.distance_, hypot(4.0 - static_cast<double>(cell.x_),
00068 4.0 - static_cast<double>(cell.y_)));
00069 count++;
00070 }
00071 EXPECT_EQ(count, 25);
00072 }
00073
00074 TEST(CostmapQueue, bigTest)
00075 {
00076 nav_grid::NavGridInfo big_info;
00077 big_info.width = 500;
00078 big_info.height = 500;
00079
00080 nav_core2::BasicCostmap big_map;
00081 big_map.setInfo(big_info);
00082 costmap_queue::CostmapQueue q(big_map);
00083 int count = 0;
00084 q.enqueueCell(0, 0);
00085 while (!q.isEmpty())
00086 {
00087 costmap_queue::CellData cell = q.getNextCell();
00088 EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
00089 count++;
00090 }
00091 EXPECT_EQ(count, 500 * 500);
00092 }
00093
00094 TEST(CostmapQueue, linearQueue)
00095 {
00096 costmap_queue::CostmapQueue q(costmap);
00097 int count = 0;
00098 q.enqueueCell(0, 0);
00099 q.enqueueCell(0, 1);
00100 q.enqueueCell(0, 2);
00101 q.enqueueCell(0, 3);
00102 q.enqueueCell(0, 4);
00103 while (!q.isEmpty())
00104 {
00105 costmap_queue::CellData cell = q.getNextCell();
00106 EXPECT_FLOAT_EQ(cell.distance_, cell.x_);
00107 count++;
00108 }
00109 EXPECT_EQ(count, 25);
00110 }
00111
00112 TEST(CostmapQueue, crossQueue)
00113 {
00114 costmap_queue::CostmapQueue q(costmap);
00115 int count = 0;
00116 int xs[] = {1, 2, 2, 3};
00117 int ys[] = {2, 1, 3, 2};
00118 int N = 4;
00119 for (int i = 0; i < N; i++)
00120 {
00121 q.enqueueCell(xs[i], ys[i]);
00122 }
00123
00124 while (!q.isEmpty())
00125 {
00126 costmap_queue::CellData cell = q.getNextCell();
00127 double min_d = 1000;
00128
00129 for (int i = 0; i < N; i++)
00130 {
00131 double dd = hypot(xs[i] - static_cast<float>(cell.x_), ys[i] - static_cast<float>(cell.y_));
00132 min_d = std::min(min_d, dd);
00133 }
00134 EXPECT_FLOAT_EQ(cell.distance_, min_d);
00135 count++;
00136 }
00137 EXPECT_EQ(count, 25);
00138 }
00139
00140 TEST(CostmapQueue, limitedQueue)
00141 {
00142 costmap_queue::LimitedCostmapQueue q(costmap, 5);
00143 int count = 0;
00144 q.enqueueCell(0, 0);
00145 while (!q.isEmpty())
00146 {
00147 costmap_queue::CellData cell = q.getNextCell();
00148 EXPECT_FLOAT_EQ(cell.distance_, hypot(cell.x_, cell.y_));
00149 count++;
00150 }
00151 EXPECT_EQ(count, 24);
00152
00153 costmap_queue::LimitedCostmapQueue q2(costmap, 3);
00154 count = 0;
00155 q2.enqueueCell(0, 0);
00156 while (!q2.isEmpty())
00157 {
00158 q2.getNextCell();
00159 count++;
00160 }
00161 EXPECT_EQ(count, 11);
00162 }
00163
00164
00165 TEST(CostmapQueue, changingSize)
00166 {
00167 nav_grid::NavGridInfo info0;
00168 info0.width = 2;
00169 info0.height = 3;
00170
00171 nav_grid::NavGridInfo info1;
00172 info1.width = 6;
00173 info1.height = 7;
00174
00175 nav_core2::BasicCostmap size_map;
00176 size_map.setInfo(info0);
00177 costmap_queue::CostmapQueue q(size_map);
00178 unsigned int count = 0;
00179 q.enqueueCell(0, 0);
00180 while (!q.isEmpty())
00181 {
00182 q.getNextCell();
00183 count++;
00184 }
00185
00186 EXPECT_EQ(count, info0.width * info0.height);
00187
00188 size_map.setInfo(info1);
00189 q.reset();
00190 count = 0;
00191 q.enqueueCell(0, 0);
00192 while (!q.isEmpty())
00193 {
00194 q.getNextCell();
00195 count++;
00196 }
00197 EXPECT_EQ(count, info1.width * info1.height);
00198 }
00199
00200 int main(int argc, char **argv)
00201 {
00202 testing::InitGoogleTest(&argc, argv);
00203 nav_grid::NavGridInfo info;
00204 info.width = 5;
00205 info.height = 5;
00206 costmap.setInfo(info);
00207 return RUN_ALL_TESTS();
00208 }