coordinates_test.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2019, 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 
00035 // Tests ripped from https://github.com/locusrobotics/robot_navigation/blob/master/nav_grid/test/utest.cpp
00036 
00037 #include <gtest/gtest.h>
00038 #include <costmap_2d/costmap_2d.h>
00039 
00040 using namespace costmap_2d;
00041 
00042 TEST(CostmapCoordinates, easy_coordinates_test)
00043 {
00044   Costmap2D costmap(2, 3, 1.0, 0, 0);
00045 
00046   double wx, wy;
00047   costmap.mapToWorld(0u, 0u, wx, wy);
00048   EXPECT_DOUBLE_EQ(wx, 0.5);
00049   EXPECT_DOUBLE_EQ(wy, 0.5);
00050   costmap.mapToWorld(1u, 2u, wx, wy);
00051   EXPECT_DOUBLE_EQ(wx, 1.5);
00052   EXPECT_DOUBLE_EQ(wy, 2.5);
00053 
00054   unsigned int umx, umy;
00055   int mx, my;
00056   ASSERT_TRUE(costmap.worldToMap(wx, wy, umx, umy));
00057   EXPECT_EQ(umx, 1);
00058   EXPECT_EQ(umy, 2);
00059   costmap.worldToMapNoBounds(wx, wy, mx, my);
00060   EXPECT_EQ(mx, 1);
00061   EXPECT_EQ(my, 2);
00062 
00063   // Invalid Coordinate
00064   wx = 2.5;
00065   EXPECT_FALSE(costmap.worldToMap(wx, wy, umx, umy));
00066   costmap.worldToMapEnforceBounds(wx, wy, mx, my);
00067   EXPECT_EQ(mx, 1);
00068   EXPECT_EQ(my, 2);
00069   costmap.worldToMapNoBounds(wx, wy, mx, my);
00070   EXPECT_EQ(mx, 2);
00071   EXPECT_EQ(my, 2);
00072 
00073   // Border Cases
00074   EXPECT_TRUE(costmap.worldToMap(0.0, wy, umx, umy));
00075   EXPECT_EQ(umx, 0);
00076   EXPECT_TRUE(costmap.worldToMap(0.25, wy, umx, umy));
00077   EXPECT_EQ(umx, 0);
00078   EXPECT_TRUE(costmap.worldToMap(0.75, wy, umx, umy));
00079   EXPECT_EQ(umx, 0);
00080   EXPECT_TRUE(costmap.worldToMap(0.9999, wy, umx, umy));
00081   EXPECT_EQ(umx, 0);
00082   EXPECT_TRUE(costmap.worldToMap(1.0, wy, umx, umy));
00083   EXPECT_EQ(umx, 1);
00084   EXPECT_TRUE(costmap.worldToMap(1.25, wy, umx, umy));
00085   EXPECT_EQ(umx, 1);
00086   EXPECT_TRUE(costmap.worldToMap(1.75, wy, umx, umy));
00087   EXPECT_EQ(umx, 1);
00088   EXPECT_TRUE(costmap.worldToMap(1.9999, wy, umx, umy));
00089   EXPECT_EQ(umx, 1);
00090   EXPECT_FALSE(costmap.worldToMap(2.0, wy, umx, umy));
00091   costmap.worldToMapEnforceBounds(2.0, wy, mx, my);
00092   EXPECT_EQ(mx, 1);
00093 }
00094 
00095 TEST(CostmapCoordinates, hard_coordinates_test)
00096 {
00097   Costmap2D costmap(2, 3, 0.1, -0.2, 0.2);
00098 
00099   double wx, wy;
00100   costmap.mapToWorld(0, 0, wx, wy);
00101   EXPECT_DOUBLE_EQ(wx, -0.15);
00102   EXPECT_DOUBLE_EQ(wy, 0.25);
00103   costmap.mapToWorld(1, 2, wx, wy);
00104   EXPECT_DOUBLE_EQ(wx, -0.05);
00105   EXPECT_DOUBLE_EQ(wy, 0.45);
00106 
00107   unsigned int umx, umy;
00108   int mx, my;
00109   EXPECT_TRUE(costmap.worldToMap(wx, wy, umx, umy));
00110   EXPECT_EQ(umx, 1);
00111   EXPECT_EQ(umy, 2);
00112   costmap.worldToMapNoBounds(wx, wy, mx, my);
00113   EXPECT_EQ(mx, 1);
00114   EXPECT_EQ(my, 2);
00115 
00116   // Invalid Coordinate
00117   wx = 2.5;
00118   EXPECT_FALSE(costmap.worldToMap(wx, wy, umx, umy));
00119   costmap.worldToMapEnforceBounds(wx, wy, mx, my);
00120   EXPECT_EQ(mx, 1);
00121   EXPECT_EQ(my, 2);
00122   costmap.worldToMapNoBounds(wx, wy, mx, my);
00123   EXPECT_EQ(mx, 27);
00124   EXPECT_EQ(my, 2);
00125 }
00126 
00127 int main(int argc, char** argv)
00128 {
00129   testing::InitGoogleTest( &argc, argv );
00130   return RUN_ALL_TESTS();
00131 }
00132 


costmap_2d
Author(s): Eitan Marder-Eppstein, David V. Lu!!, Dave Hershberger, contradict@gmail.com
autogenerated on Sun Mar 3 2019 03:46:15