Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
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     
00061     
00062     
00063     
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 }