resolution_test.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2018, 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_2d_utils/path_ops.h>
00036 
00037 using nav_2d_utils::adjustPlanResolution;
00038 using nav_2d_utils::addPose;
00039 
00040 TEST(ResolutionTest, simple_example)
00041 {
00042   nav_2d_msgs::Path2D path;
00043   // Space between points is one meter
00044   addPose(path, 0.0, 0.0);
00045   addPose(path, 0.0, 1.0);
00046 
00047   // resolution>=1, path won't change
00048   EXPECT_EQ(2U, adjustPlanResolution(path, 2.0).poses.size());
00049   EXPECT_EQ(2U, adjustPlanResolution(path, 1.0).poses.size());
00050 
00051   // 0.5 <= resolution < 1.0, one point should be added in the middle
00052   EXPECT_EQ(3U, adjustPlanResolution(path, 0.8).poses.size());
00053   EXPECT_EQ(3U, adjustPlanResolution(path, 0.5).poses.size());
00054 
00055   // 0.333 <= resolution < 0.5, two points need to be added
00056   EXPECT_EQ(4U, adjustPlanResolution(path, 0.34).poses.size());
00057 
00058   // 0.25 <= resolution < 0.333, three points need to be added
00059   EXPECT_EQ(5U, adjustPlanResolution(path, 0.32).poses.size());
00060 }
00061 
00062 TEST(ResolutionTest, real_example)
00063 {
00064   // This test is based on a real-world example
00065   nav_2d_msgs::Path2D path;
00066   addPose(path, 17.779193, -0.972024);
00067   addPose(path, 17.799171, -0.950775);
00068   addPose(path, 17.851942, -0.903709);
00069   EXPECT_EQ(3U, adjustPlanResolution(path, 0.2).poses.size());
00070   EXPECT_EQ(4U, adjustPlanResolution(path, 0.05).poses.size());
00071 }
00072 
00073 
00074 int main(int argc, char** argv)
00075 {
00076   testing::InitGoogleTest(&argc, argv);
00077   return RUN_ALL_TESTS();
00078 }


nav_2d_utils
Author(s):
autogenerated on Wed Jun 26 2019 20:09:36