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 #include <laser_joint_processor/joint_image_interpolator.h>
00037
00038 using namespace std;
00039 using namespace laser_joint_processor;
00040
00041 static const float eps = 1e-6;
00042
00043 class InterpSnapshot_EasyTests : public ::testing::Test
00044 {
00045 protected:
00046 virtual void SetUp()
00047 {
00048 snapshot_.angle_min = 10.0;
00049 snapshot_.angle_increment = 1.0;
00050 snapshot_.readings_per_scan = 4;
00051 snapshot_.num_scans = 3;
00052 snapshot_.ranges.resize(12);
00053 for (unsigned int i=0; i<snapshot_.ranges.size(); i++)
00054 snapshot_.ranges[i] = i*100;
00055
00056 points_.resize(7);
00057
00058
00059 points_[0] = Point(0,0);
00060 points_[1] = Point(3,0);
00061 points_[2] = Point(0,2);
00062 points_[3] = Point(3,2);
00063
00064 points_[4] = Point(2.5, .5);
00065 points_[5] = Point(2, 1);
00066 points_[6] = Point(1.25, 1.5);
00067
00068 bool result;
00069 result = interpSnapshot(points_, snapshot_, angles_, ranges_);
00070 ASSERT_TRUE(result);
00071 }
00072
00073 geometry_msgs::Point Point(float x, float y)
00074 {
00075 geometry_msgs::Point point;
00076 point.x = x;
00077 point.y = y;
00078 return point;
00079 }
00080
00081 std::vector <geometry_msgs::Point> points_;
00082 vector<float> angles_;
00083 vector<float> ranges_;
00084 calibration_msgs::DenseLaserSnapshot snapshot_;
00085 };
00086
00087 TEST_F(InterpSnapshot_EasyTests, angles)
00088 {
00089 EXPECT_NEAR(angles_[0], 10.0, eps);
00090 EXPECT_NEAR(angles_[1], 13.0, eps);
00091 EXPECT_NEAR(angles_[2], 10.0, eps);
00092 EXPECT_NEAR(angles_[3], 13.0, eps);
00093 EXPECT_NEAR(angles_[4], 12.5, eps);
00094 EXPECT_NEAR(angles_[5], 12.0, eps);
00095 EXPECT_NEAR(angles_[6], 11.25,eps);
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 TEST_F(InterpSnapshot_EasyTests, ranges)
00106 {
00107 EXPECT_NEAR(ranges_[0], 0.0, eps);
00108 EXPECT_NEAR(ranges_[1], 300.0, eps);
00109 EXPECT_NEAR(ranges_[2], 800.0, eps);
00110 EXPECT_NEAR(ranges_[3], 1100.0, eps);
00111 EXPECT_NEAR(ranges_[4], 450.0, eps);
00112 EXPECT_NEAR(ranges_[5], 600.0, eps);
00113 EXPECT_NEAR(ranges_[6], 725.0, eps);
00114 }
00115
00116 TEST_F(InterpSnapshot_EasyTests, out_of_bounds)
00117 {
00118 points_[6] = Point(-1.0, 0);
00119 EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
00120
00121 points_[6] = Point(0, -1.0);
00122 EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
00123
00124 points_[6] = Point(3.1, 1.9);
00125 EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
00126
00127 points_[6] = Point(2.9, 2.1);
00128 EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
00129
00130
00131 points_[6] = Point(1, 1);
00132 EXPECT_TRUE(interpSnapshot(points_, snapshot_, angles_, ranges_));
00133 }
00134
00135
00136
00137 int main(int argc, char **argv){
00138 testing::InitGoogleTest(&argc, argv);
00139 return RUN_ALL_TESTS();
00140 }