interp_snapshot_unittest.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <gtest/gtest.h>
37 
38 using namespace std;
39 using namespace laser_joint_processor;
40 
41 static const float eps = 1e-6;
42 
43 class InterpSnapshot_EasyTests : public ::testing::Test
44 {
45 protected:
46  virtual void SetUp()
47  {
48  snapshot_.angle_min = 10.0;
49  snapshot_.angle_increment = 1.0;
50  snapshot_.readings_per_scan = 4;
51  snapshot_.num_scans = 3;
52  snapshot_.ranges.resize(12);
53  for (unsigned int i=0; i<snapshot_.ranges.size(); i++)
54  snapshot_.ranges[i] = i*100;
55 
56  points_.resize(7);
57 
58  // Boundaries
59  points_[0] = Point(0,0);
60  points_[1] = Point(3,0);
61  points_[2] = Point(0,2);
62  points_[3] = Point(3,2);
63 
64  points_[4] = Point(2.5, .5);
65  points_[5] = Point(2, 1);
66  points_[6] = Point(1.25, 1.5);
67 
68  bool result;
69  result = interpSnapshot(points_, snapshot_, angles_, ranges_);
70  ASSERT_TRUE(result);
71  }
72 
73  geometry_msgs::Point Point(float x, float y)
74  {
75  geometry_msgs::Point point;
76  point.x = x;
77  point.y = y;
78  return point;
79  }
80 
81  std::vector <geometry_msgs::Point> points_;
82  vector<float> angles_;
83  vector<float> ranges_;
84  calibration_msgs::DenseLaserSnapshot snapshot_;
85 };
86 
88 {
89  EXPECT_NEAR(angles_[0], 10.0, eps);
90  EXPECT_NEAR(angles_[1], 13.0, eps);
91  EXPECT_NEAR(angles_[2], 10.0, eps);
92  EXPECT_NEAR(angles_[3], 13.0, eps);
93  EXPECT_NEAR(angles_[4], 12.5, eps);
94  EXPECT_NEAR(angles_[5], 12.0, eps);
95  EXPECT_NEAR(angles_[6], 11.25,eps);
96 }
97 
98 
99 /*
100  * 0 100 200 300
101  * 400 500 600 700
102  * 800 900 1000 1100
103  */
104 
106 {
107  EXPECT_NEAR(ranges_[0], 0.0, eps);
108  EXPECT_NEAR(ranges_[1], 300.0, eps);
109  EXPECT_NEAR(ranges_[2], 800.0, eps);
110  EXPECT_NEAR(ranges_[3], 1100.0, eps);
111  EXPECT_NEAR(ranges_[4], 450.0, eps);
112  EXPECT_NEAR(ranges_[5], 600.0, eps);
113  EXPECT_NEAR(ranges_[6], 725.0, eps);
114 }
115 
117 {
118  points_[6] = Point(-1.0, 0);
119  EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
120 
121  points_[6] = Point(0, -1.0);
122  EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
123 
124  points_[6] = Point(3.1, 1.9);
125  EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
126 
127  points_[6] = Point(2.9, 2.1);
128  EXPECT_FALSE(interpSnapshot(points_, snapshot_, angles_, ranges_));
129 
130  // Control Test
131  points_[6] = Point(1, 1);
132  EXPECT_TRUE(interpSnapshot(points_, snapshot_, angles_, ranges_));
133 }
134 
135 
136 
137 int main(int argc, char **argv){
138  testing::InitGoogleTest(&argc, argv);
139  return RUN_ALL_TESTS();
140 }
int main(int argc, char **argv)
TEST_F(InterpSnapshot_EasyTests, angles)
bool interpSnapshot(const std::vector< geometry_msgs::Point > &points, const calibration_msgs::DenseLaserSnapshot &snapshot, std::vector< float > &pointing_angles, std::vector< float > &ranges)
calibration_msgs::DenseLaserSnapshot snapshot_
std::vector< geometry_msgs::Point > points_
static const float eps
geometry_msgs::Point Point(float x, float y)


laser_joint_processor
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:55