laser_interval_calc_unittest.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
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 Willow Garage 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 OWNER 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 #include <gtest/gtest.h>
00036 
00037 #include <laser_cb_detector/laser_interval_calc.h>
00038 
00039 using namespace std;
00040 using namespace laser_cb_detector;
00041 
00042 static const bool DEBUG=false;
00043 
00044 static const float eps = 1e-6;
00045 
00046 class LaserIntervalCalcTest : public ::testing::Test
00047 {
00048 protected:
00049   virtual void SetUp()
00050   {
00051     snapshot_.header.stamp = ros::Time(10,0);
00052     snapshot_.time_increment = 1.0;
00053     snapshot_.readings_per_scan = 4;
00054     snapshot_.num_scans = 3;
00055     snapshot_.scan_start.resize(3);
00056     snapshot_.scan_start[0] = ros::Time(20);
00057     snapshot_.scan_start[1] = ros::Time(40);
00058     snapshot_.scan_start[2] = ros::Time(30);
00059 
00060     // Snapshot Times:
00061     // 20  21  22  23  24
00062     // 40  41  42  43  44
00063     // 30  31  32  33  34
00064   }
00065 
00066   calibration_msgs::DenseLaserSnapshot snapshot_;
00067   calibration_msgs::CalibrationPattern features_;
00068   calibration_msgs::Interval interval_;
00069 };
00070 
00071 #define EXPECT_ROSTIME_NEAR(a, b) \
00072   EXPECT_NEAR( (a-b).toSec(), 0.0, eps) \
00073      << "Times don't match: #a: " << a.toSec() << "   " << "#b: " << b.toSec()
00074 
00075 TEST_F(LaserIntervalCalcTest, easy_single_point)
00076 {
00077   bool success;
00078   features_.image_points.resize(1);
00079   features_.image_points[0].x = .5;
00080   features_.image_points[0].y = 1.5;
00081   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00082   EXPECT_TRUE(success);
00083   EXPECT_ROSTIME_NEAR(interval_.start, ros::Time(30,0));
00084   EXPECT_ROSTIME_NEAR(interval_.end,   ros::Time(41,0));
00085 }
00086 
00087 TEST_F(LaserIntervalCalcTest, corners)
00088 {
00089   bool success;
00090   features_.image_points.resize(1);
00091   features_.image_points[0].x =  .5;
00092   features_.image_points[0].y = 0.01;
00093   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00094   EXPECT_TRUE(success);
00095   EXPECT_ROSTIME_NEAR(interval_.start, ros::Time(20,0));
00096   EXPECT_ROSTIME_NEAR(interval_.end,   ros::Time(41,0));
00097 
00098   features_.image_points[0].y = -0.01;
00099   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00100   EXPECT_FALSE(success);
00101 
00102   features_.image_points[0].y = 2.01;
00103   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00104   EXPECT_FALSE(success);
00105 }
00106 
00107 TEST_F(LaserIntervalCalcTest, empty)
00108 {
00109   bool success;
00110   features_.image_points.clear();
00111   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00112   EXPECT_TRUE(success);
00113   EXPECT_ROSTIME_NEAR(interval_.start, ros::Time(10,0));
00114   EXPECT_ROSTIME_NEAR(interval_.end,   ros::Time(10,0));
00115 }
00116 
00117 TEST_F(LaserIntervalCalcTest, easy_multi_point)
00118 {
00119   bool success;
00120   features_.image_points.resize(3);
00121   features_.image_points[0].x =  .5;
00122   features_.image_points[0].y =  .5;
00123   features_.image_points[1].x = 3.5;
00124   features_.image_points[1].y =  .5;
00125   features_.image_points[2].x = 3.5;
00126   features_.image_points[2].y = 1.5;
00127 
00128   success = LaserIntervalCalc::computeInterval(snapshot_, features_, interval_);
00129   EXPECT_TRUE(success);
00130   EXPECT_ROSTIME_NEAR(interval_.start, ros::Time(20,0));
00131   EXPECT_ROSTIME_NEAR(interval_.end,   ros::Time(44,0));
00132 }
00133 
00134 int main(int argc, char **argv)
00135 {
00136   testing::InitGoogleTest(&argc, argv);
00137   return RUN_ALL_TESTS();
00138 }


laser_cb_detector
Author(s): Vijay Pradeep
autogenerated on Sun Oct 5 2014 22:43:14