utest.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
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 }


costmap_queue
Author(s):
autogenerated on Wed Jun 26 2019 20:09:33