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 <settlerlib/deflated.h>
00037
00038 using namespace std;
00039 using namespace settlerlib;
00040
00041 static const double eps = 1e-6;
00042
00043 TEST(Deflated, easy1)
00044 {
00045 Deflated before, after;
00046 before.header.stamp = ros::Time(0,0);
00047 after.header.stamp = ros::Time(10,0);
00048
00049 before.channels_.resize(2);
00050 after.channels_.resize(2);
00051
00052 before.channels_[0] = 0;
00053 after.channels_[0] = 100;
00054
00055 before.channels_[1] = 1000;
00056 after.channels_[1] = 0;
00057
00058 vector<double> middle;
00059 bool success;
00060 success = Deflated::interp(before, after, ros::Time(0,0), middle);
00061 EXPECT_TRUE(success);
00062 EXPECT_NEAR(middle[0], 0, eps);
00063 EXPECT_NEAR(middle[1], 1000, eps);
00064
00065 success = Deflated::interp(before, after, ros::Time(1,0), middle);
00066 EXPECT_TRUE(success);
00067 EXPECT_NEAR(middle[0], 10, eps);
00068 EXPECT_NEAR(middle[1], 900, eps);
00069
00070 success = Deflated::interp(before, after, ros::Time(10,0), middle);
00071 EXPECT_TRUE(success);
00072 EXPECT_NEAR(middle[0], 100, eps);
00073 EXPECT_NEAR(middle[1], 0, eps);
00074
00075 EXPECT_TRUE(true);
00076 }
00077
00078 TEST(Deflated, zeroInterval)
00079 {
00080 Deflated before, after;
00081 before.header.stamp = ros::Time(10,0);
00082 after.header.stamp = ros::Time(10,0);
00083 before.channels_.resize(2);
00084 after.channels_.resize(2);
00085
00086 before.channels_[0] = 10;
00087 after.channels_[0] = 10;
00088
00089 before.channels_[1] = 20;
00090 after.channels_[1] = 20;
00091
00092 vector<double> middle;
00093 bool success;
00094 success = Deflated::interp(before, after, ros::Time(10,0), middle);
00095 EXPECT_TRUE(success);
00096
00097 EXPECT_NEAR(middle[0], 10, eps);
00098 EXPECT_NEAR(middle[1], 20, eps);
00099 }
00100
00101 TEST(Deflated, sizeMismatch)
00102 {
00103 Deflated before, after;
00104 before.header.stamp = ros::Time(0,0);
00105 after.header.stamp = ros::Time(10,0);
00106 before.channels_.resize(2);
00107 after.channels_.resize(3);
00108
00109 vector<double> middle;
00110 bool success;
00111 success = Deflated::interp(before, after, ros::Time(0,0), middle);
00112 EXPECT_FALSE(success);
00113 }
00114
00115 TEST(Deflated, badIntervals)
00116 {
00117 Deflated before, after;
00118 before.channels_.resize(3);
00119 after.channels_.resize(3);
00120
00121 vector<double> middle;
00122
00123 before.header.stamp = ros::Time(10,0);
00124 after.header.stamp = ros::Time(20,0);
00125 EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
00126 EXPECT_TRUE( Deflated::interp(before, after, ros::Time(15,0), middle));
00127 EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
00128
00129 before.header.stamp = ros::Time(20,0);
00130 after.header.stamp = ros::Time(10,0);
00131 EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
00132 EXPECT_FALSE(Deflated::interp(before, after, ros::Time(15,0), middle));
00133 EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
00134 }
00135
00136
00137
00138 int main(int argc, char **argv){
00139 testing::InitGoogleTest(&argc, argv);
00140 return RUN_ALL_TESTS();
00141 }