00001
00009
00010
00011
00012
00013 #include <string>
00014 #include <gtest/gtest.h>
00015 #include <ecl/containers/array.hpp>
00016 #include "../../include/ecl/geometry/cubic_spline.hpp"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 using std::string;
00028 using ecl::Array;
00029
00030
00031 using ecl::CubicPolynomial;
00032 using ecl::CubicSpline;
00033
00034
00035
00036
00037
00038 TEST(CubicSplinesTests,derivativeHeuristic) {
00039 Array<double> x_set(3);
00040 Array<double> y_set(3);
00041 x_set << 0.688792, 1.15454, 1.67894;
00042 y_set << -0.75, -1.2, -1.30;
00043 double ydot_0 = -0.5/x_set[0];
00044 double ydot_f = 1.04/3.72;
00045
00046 CubicSpline cubic = CubicSpline::DerivativeHeuristic(x_set, y_set, ydot_0, ydot_f);
00047
00048
00049
00050
00051
00052 const Array<double>& domain = cubic.domain();
00053 EXPECT_EQ(0.688792, domain[0]);
00054 EXPECT_EQ(1.15454, domain[1]);
00055 EXPECT_EQ(1.67894, domain[2]);
00056 const CubicPolynomial &p1 = cubic.polynomials()[0];
00057 const CubicPolynomial &p2 = cubic.polynomials()[1];
00058
00059 EXPECT_GT(-2.07,p1.coefficients()[0]); EXPECT_LT(-2.09,p1.coefficients()[0]);
00060 EXPECT_GT(5.97,p1.coefficients()[1]); EXPECT_LT(5.95,p1.coefficients()[1]);
00061 EXPECT_GT(-7.84,p1.coefficients()[2]); EXPECT_LT(-7.86,p1.coefficients()[2]);
00062 EXPECT_GT(2.91,p1.coefficients()[3]); EXPECT_LT(2.89,p1.coefficients()[3]);
00063
00064 EXPECT_GT(-0.21,p2.coefficients()[0]); EXPECT_LT(-0.23,p2.coefficients()[0]);
00065 EXPECT_GT(-0.71,p2.coefficients()[1]); EXPECT_LT(-0.73,p2.coefficients()[1]);
00066 EXPECT_GT(-0.45,p2.coefficients()[2]); EXPECT_LT(-0.47,p2.coefficients()[2]);
00067 EXPECT_GT(0.31,p2.coefficients()[3]); EXPECT_LT(0.29,p2.coefficients()[3]);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 }
00087
00088
00089 TEST(CubicSplinesTests,continuousHeuristic) {
00090 Array<double> x_set(3);
00091 Array<double> y_set(3);
00092 x_set << 0.688792, 1.15454, 1.67894;
00093 y_set << -0.75, -1.2, -1.30;
00094 double ydot_0 = -0.5/x_set[0];
00095 double ydot_f = 1.04/3.72;
00096 CubicSpline cubic = CubicSpline::ContinuousDerivatives(x_set, y_set, ydot_0, ydot_f);
00097 const CubicPolynomial &p1 = cubic.polynomials()[0];
00098 const CubicPolynomial &p2 = cubic.polynomials()[1];
00099
00100 EXPECT_GT(-1.57,p1.coefficients()[0]); EXPECT_LT(-1.59,p1.coefficients()[0]);
00101 EXPECT_GT(4.10,p1.coefficients()[1]); EXPECT_LT(4.08,p1.coefficients()[1]);
00102 EXPECT_GT(-5.53,p1.coefficients()[2]); EXPECT_LT(-5.55,p1.coefficients()[2]);
00103 EXPECT_GT(2.00,p1.coefficients()[3]); EXPECT_LT(1.98,p1.coefficients()[3]);
00104
00105 EXPECT_GT(2.13,p2.coefficients()[0]); EXPECT_LT(2.11,p2.coefficients()[0]);
00106 EXPECT_GT(-5.51,p2.coefficients()[1]); EXPECT_LT(-5.53,p2.coefficients()[1]);
00107 EXPECT_GT(2.79,p2.coefficients()[2]); EXPECT_LT(2.77,p2.coefficients()[2]);
00108 EXPECT_GT(-0.41,p2.coefficients()[3]); EXPECT_LT(-0.43,p2.coefficients()[3]);
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }
00128
00129 TEST(CubicSplinesTests,naturalSpline) {
00130 Array<double> x_set(3);
00131 Array<double> y_set(3);
00132 x_set << 0.688792, 1.15454, 1.67894;
00133 y_set << -0.75, -1.2, -1.30;
00134
00135 CubicSpline cubic = CubicSpline::Natural(x_set, y_set);
00136 const CubicPolynomial &p1 = cubic.polynomials()[0];
00137 const CubicPolynomial &p2 = cubic.polynomials()[1];
00138
00139 EXPECT_GT(-0.22,p1.coefficients()[0]); EXPECT_LT(-0.24,p1.coefficients()[0]);
00140 EXPECT_GT(0.06,p1.coefficients()[1]); EXPECT_LT(0.04,p1.coefficients()[1]);
00141 EXPECT_GT(-1.73,p1.coefficients()[2]); EXPECT_LT(-1.75,p1.coefficients()[2]);
00142 EXPECT_GT(0.85,p1.coefficients()[3]); EXPECT_LT(0.83,p1.coefficients()[3]);
00143
00144 EXPECT_GT(2.22,p2.coefficients()[0]); EXPECT_LT(2.20,p2.coefficients()[0]);
00145 EXPECT_GT(-6.29,p2.coefficients()[1]); EXPECT_LT(-6.31,p2.coefficients()[1]);
00146 EXPECT_GT(3.77,p2.coefficients()[2]); EXPECT_LT(3.75,p2.coefficients()[2]);
00147 EXPECT_GT(-0.74,p2.coefficients()[3]); EXPECT_LT(-0.76,p2.coefficients()[3]);
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 }
00167
00168
00169
00170
00171
00172 int main(int argc, char **argv) {
00173
00174 testing::InitGoogleTest(&argc,argv);
00175 return RUN_ALL_TESTS();
00176 }
00177
00178
00179
00180