BaseDistance_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Ingo Kresse <kresse@in.tum.de>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 
00031 #include <vector>
00032 #include <algorithm> //random_shuffle
00033 #include <math.h>
00034 #include <stdio.h>
00035 
00036 #include <assert.h>
00037 
00038 #include "BaseDistance.h"
00039 
00040 #define Vector2 BaseDistance::Vector2
00041 
00042 bool distance_test()
00043 {
00044   std::vector<Vector2> points;
00045   Vector2 n;
00046   double d, eps=0.00001;
00047 
00048   BaseDistance tester;
00049   tester.setFootprint(0.8, -0.3, 0.5, -0.7, 0.1);
00050 
00051   // edge cases
00052   points.push_back(Vector2(3.2f, 0.0f));
00053   d = tester.distance(points, &n);
00054   assert((d-2.4)<eps && n.x == 3.2f && n.y == 0.0f);
00055 
00056   points.push_back(Vector2(0.0f, 2.8f));
00057   d = tester.distance(points, &n);
00058   assert((d-2.3 < eps) && n.x == 0.0f && n.y == 2.8f);
00059 
00060   points.push_back(Vector2(0.0f, -2.9f));
00061   d = tester.distance(points, &n);
00062   assert((d-2.2 < eps) && n.x == 0.0f && n.y == -2.9f);
00063 
00064   points.push_back(Vector2(-2.4f, 0.0f));
00065   d = tester.distance(points, &n);
00066   assert((d-2.1 < eps) && n.x == -2.4f && n.y == 0.0f);
00067 
00068 
00069   // corner cases
00070   points.push_back(Vector2(1.76f, 1.6f));
00071   d = tester.distance(points, &n);
00072   assert((d-1.46 < eps) && n.x == 1.76f && n.y == 1.6f);
00073 
00074   points.push_back(Vector2(-1.18f, 1.55f));
00075   d = tester.distance(points, &n);
00076   assert((d-1.37 < eps) && n.x == -1.18f && n.y == 1.55f);
00077 
00078   points.push_back(Vector2(-1.05f, -1.7f));
00079   d = tester.distance(points, &n);
00080   assert((d-1.25 < eps) && n.x == -1.05f && n.y == -1.7f);
00081 
00082   points.push_back(Vector2(0.95f, -1.82f));
00083   d = tester.distance(points, &n);
00084   assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
00085 
00086 
00087   // check if the order matters - it should not.
00088   for(int i=0; i < 1000; i++) {
00089     std::random_shuffle(points.begin(), points.end());
00090     d = tester.distance(points, &n);
00091     assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
00092   }
00093   return true;
00094 }
00095 
00096 int main(int argc, char *argv[])
00097 {
00098   ros::init(argc, argv, "BaseDistance_test");
00099   distance_test();
00100 }


nav_pcontroller
Author(s): Ingo Kresse
autogenerated on Wed Aug 2 2017 02:30:35