deflated_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>
36 #include <settlerlib/deflated.h>
37 
38 using namespace std;
39 using namespace settlerlib;
40 
41 static const double eps = 1e-6;
42 
43 TEST(Deflated, easy1)
44 {
45  Deflated before, after;
46  before.header.stamp = ros::Time(0,0);
47  after.header.stamp = ros::Time(10,0);
48 
49  before.channels_.resize(2);
50  after.channels_.resize(2);
51 
52  before.channels_[0] = 0;
53  after.channels_[0] = 100;
54 
55  before.channels_[1] = 1000;
56  after.channels_[1] = 0;
57 
58  vector<double> middle;
59  bool success;
60  success = Deflated::interp(before, after, ros::Time(0,0), middle);
61  EXPECT_TRUE(success);
62  EXPECT_NEAR(middle[0], 0, eps);
63  EXPECT_NEAR(middle[1], 1000, eps);
64 
65  success = Deflated::interp(before, after, ros::Time(1,0), middle);
66  EXPECT_TRUE(success);
67  EXPECT_NEAR(middle[0], 10, eps);
68  EXPECT_NEAR(middle[1], 900, eps);
69 
70  success = Deflated::interp(before, after, ros::Time(10,0), middle);
71  EXPECT_TRUE(success);
72  EXPECT_NEAR(middle[0], 100, eps);
73  EXPECT_NEAR(middle[1], 0, eps);
74 
75  EXPECT_TRUE(true);
76 }
77 
78 TEST(Deflated, zeroInterval)
79 {
80  Deflated before, after;
81  before.header.stamp = ros::Time(10,0);
82  after.header.stamp = ros::Time(10,0);
83  before.channels_.resize(2);
84  after.channels_.resize(2);
85 
86  before.channels_[0] = 10;
87  after.channels_[0] = 10;
88 
89  before.channels_[1] = 20;
90  after.channels_[1] = 20;
91 
92  vector<double> middle;
93  bool success;
94  success = Deflated::interp(before, after, ros::Time(10,0), middle);
95  EXPECT_TRUE(success);
96 
97  EXPECT_NEAR(middle[0], 10, eps);
98  EXPECT_NEAR(middle[1], 20, eps);
99 }
100 
101 TEST(Deflated, sizeMismatch)
102 {
103  Deflated before, after;
104  before.header.stamp = ros::Time(0,0);
105  after.header.stamp = ros::Time(10,0);
106  before.channels_.resize(2);
107  after.channels_.resize(3);
108 
109  vector<double> middle;
110  bool success;
111  success = Deflated::interp(before, after, ros::Time(0,0), middle);
112  EXPECT_FALSE(success);
113 }
114 
115 TEST(Deflated, badIntervals)
116 {
117  Deflated before, after;
118  before.channels_.resize(3);
119  after.channels_.resize(3);
120 
121  vector<double> middle;
122 
123  before.header.stamp = ros::Time(10,0);
124  after.header.stamp = ros::Time(20,0);
125  EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
126  EXPECT_TRUE( Deflated::interp(before, after, ros::Time(15,0), middle));
127  EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
128 
129  before.header.stamp = ros::Time(20,0);
130  after.header.stamp = ros::Time(10,0);
131  EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
132  EXPECT_FALSE(Deflated::interp(before, after, ros::Time(15,0), middle));
133  EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
134 }
135 
136 
137 
138 int main(int argc, char **argv){
139  testing::InitGoogleTest(&argc, argv);
140  return RUN_ALL_TESTS();
141 }
int main(int argc, char **argv)
std_msgs::Header header
Definition: deflated.h:47
std::vector< double > channels_
Definition: deflated.h:48
static const double eps
TEST(Deflated, easy1)


settlerlib
Author(s): Vijay Pradeep
autogenerated on Fri Apr 2 2021 02:12:59