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/interval_calc.h>
00037 #include <settlerlib/sorted_deque.h>
00038
00039 using namespace std;
00040 using namespace settlerlib;
00041
00042
00043 const unsigned int NA = 9;
00044 static const double dataA[NA][2] = { { 0, 0},
00045 { 1, 1},
00046 { 2, 2},
00047 { 3, 3},
00048 { 4, 4},
00049 { 3, 5},
00050 { 2, 6},
00051 { 1, 7},
00052 { 0, 8} };
00053
00057 SortedDeque<DeflatedConstPtr> generateSignal1()
00058 {
00059 SortedDeque<DeflatedConstPtr> signal(&SortedDeque<DeflatedConstPtr>::getPtrStamp) ;
00060 signal.setMaxSize(20);
00061
00062 for (unsigned int i=0; i<NA; i++)
00063 {
00064 DeflatedPtr deflated(new Deflated);
00065 deflated->header.stamp = ros::Time(i,0);
00066 deflated->channels_.resize(2);
00067 deflated->channels_[0] = dataA[i][0];
00068 deflated->channels_[1] = dataA[i][1];
00069
00070 signal.add(deflated);
00071 }
00072
00073 return signal;
00074 }
00075
00079 SortedDeque<DeflatedConstPtr> generateSignal2()
00080 {
00081
00082 SortedDeque<DeflatedConstPtr> signal(&SortedDeque<DeflatedConstPtr>::getPtrStamp) ;
00083 signal.setMaxSize(20);
00084
00085 for (unsigned int i=0; i<NA; i++)
00086 {
00087 DeflatedPtr deflated(new Deflated);
00088 deflated->header.stamp = ros::Time(i,0);
00089 if (i > 4)
00090 deflated->header.stamp = ros::Time(i+10,0);
00091 else
00092 deflated->header.stamp = ros::Time(i,0);
00093 deflated->channels_.resize(2);
00094 deflated->channels_[0] = dataA[i][0];
00095 deflated->channels_[1] = dataA[i][1];
00096
00097 signal.add(deflated);
00098 }
00099
00100 return signal;
00101 }
00102
00103
00104 TEST(IntervalCalc, easy1)
00105 {
00106 SortedDeque<DeflatedConstPtr> signal = generateSignal1();
00107
00108 vector<double> tol(2);
00109 tol[0] = 2.5;
00110 tol[1] = 3.5;
00111 ros::Duration max_step(2,0);
00112
00113 calibration_msgs::Interval interval = IntervalCalc::computeLatestInterval(signal, tol, max_step);
00114 EXPECT_EQ(interval.start.sec, (unsigned int) 6);
00115 EXPECT_EQ(interval.end.sec, (unsigned int) 8);
00116 }
00117
00118
00119 TEST(IntervalCalc, easy2)
00120 {
00121 SortedDeque<DeflatedConstPtr> signal = generateSignal1();
00122
00123 vector<double> tol(2);
00124 tol[0] = 4.5;
00125 tol[1] = 3.5;
00126 ros::Duration max_step(2,0);
00127
00128 calibration_msgs::Interval interval = IntervalCalc::computeLatestInterval(signal, tol, max_step);
00129 EXPECT_EQ(interval.start.sec, (unsigned int) 5);
00130 EXPECT_EQ(interval.end.sec, (unsigned int) 8);
00131 }
00132
00133
00134 TEST(IntervalCalc, maxStep1)
00135 {
00136 SortedDeque<DeflatedConstPtr> signal = generateSignal1();
00137
00138 vector<double> tol(2);
00139 tol[0] = 4.5;
00140 tol[1] = 3.5;
00141 ros::Duration max_step;
00142 max_step.fromSec(.5);
00143
00144 calibration_msgs::Interval interval = IntervalCalc::computeLatestInterval(signal, tol, max_step);
00145 EXPECT_EQ(interval.start.sec, (unsigned int) 8);
00146 EXPECT_EQ(interval.end.sec, (unsigned int) 8);
00147 }
00148
00149
00150 TEST(IntervalCalc, maxStep2)
00151 {
00152 SortedDeque<DeflatedConstPtr> signal = generateSignal2();
00153
00154 vector<double> tol(2);
00155 tol[0] = 100;
00156 tol[1] = 100;
00157 ros::Duration max_step(5,0);
00158
00159 calibration_msgs::Interval interval = IntervalCalc::computeLatestInterval(signal, tol, max_step);
00160 EXPECT_EQ(interval.start.sec, (unsigned int) 15);
00161 EXPECT_EQ(interval.end.sec, (unsigned int) 18);
00162 }
00163
00164 int main(int argc, char **argv){
00165 testing::InitGoogleTest(&argc, argv);
00166 return RUN_ALL_TESTS();
00167 }