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
00037 #include <gtest/gtest.h>
00038 #include <spline_smoother/splines.h>
00039 #include <stdlib.h>
00040
00041 using namespace spline_smoother;
00042
00043 static double getRandomNumber(double min, double max)
00044 {
00045 return ((double)rand() / RAND_MAX)*(max-min) + min;
00046 }
00047
00048 TEST(TestSplines, testQuinticCoefficients)
00049 {
00050
00051 srand(0);
00052
00053
00054 double bc[6];
00055 for (int i=0; i<6; i++)
00056 bc[i] = getRandomNumber(-1.0, 1.0);
00057
00058
00059 double time = getRandomNumber(0.5,10.0);
00060
00061
00062 std::vector<double> coeffs;
00063 getQuinticSplineCoefficients(bc[0], bc[1], bc[2], bc[3], bc[4], bc[5], time, coeffs);
00064
00065
00066 double test_bc[6];
00067 sampleQuinticSpline(coeffs, 0, test_bc[0], test_bc[1], test_bc[2]);
00068 sampleQuinticSpline(coeffs, time, test_bc[3], test_bc[4], test_bc[5]);
00069
00070 double tolerance=1e-10;
00071
00072 EXPECT_NEAR(bc[0], test_bc[0], tolerance);
00073 EXPECT_NEAR(bc[1], test_bc[1], tolerance);
00074 EXPECT_NEAR(bc[2], test_bc[2], tolerance);
00075 EXPECT_NEAR(bc[3], test_bc[3], tolerance);
00076 EXPECT_NEAR(bc[4], test_bc[4], tolerance);
00077 EXPECT_NEAR(bc[5], test_bc[5], tolerance);
00078 }
00079
00080 TEST(TestSplines, testCubicCoefficients)
00081 {
00082
00083 srand(1);
00084
00085
00086 double bc[4];
00087 for (int i=0; i<4; i++)
00088 bc[i] = getRandomNumber(-1.0, 1.0);
00089
00090
00091 double time = getRandomNumber(0.5,10.0);
00092
00093
00094 std::vector<double> coeffs;
00095 getCubicSplineCoefficients(bc[0], bc[1], bc[2], bc[3], time, coeffs);
00096
00097
00098 double test_bc[4];
00099 double dummy;
00100 sampleCubicSpline(coeffs, 0, test_bc[0], test_bc[1], dummy);
00101 sampleCubicSpline(coeffs, time, test_bc[2], test_bc[3], dummy);
00102
00103 double tolerance=1e-10;
00104
00105 EXPECT_NEAR(bc[0], test_bc[0], tolerance);
00106 EXPECT_NEAR(bc[1], test_bc[1], tolerance);
00107 EXPECT_NEAR(bc[2], test_bc[2], tolerance);
00108 EXPECT_NEAR(bc[3], test_bc[3], tolerance);
00109 }
00110
00111 int main(int argc, char** argv)
00112 {
00113 testing::InitGoogleTest(&argc, argv);
00114 return RUN_ALL_TESTS();
00115 }