This unit test tests the interpolation class but also serves as minimal example how to perform interpolation given a data and time array
#include <iostream>
#include <cstdlib>
#include <gtest/gtest.h>
TEST(InterplationTest, Linear)
{
timeStamp[0] = 0.0;
timeStamp[1] = 0.5;
timeStamp[2] = 1.0;
timeStamp[3] = 1.5;
timeStamp[4] = 2.0;
data[0] << 0.0, 0.0;
data[1] << 1.0, 0.0;
data[2] << 2.0, 0.0;
data[3] << 3.0, 0.0;
data[4] << 4.0, 0.0;
for (
int i = 1;
i < 5;
i++)
{
double enquiryTime = 0.5 *
i;
linInterpolation.
interpolate(timeStamp, data, enquiryTime, enquiryData);
std::cout << "At time " << enquiryTime << "\t data is " << enquiryData.transpose() << std::endl;
Eigen::Vector2d nominal_result;
nominal_result << double(
i), 0.0;
ASSERT_LT((nominal_result - enquiryData).array().abs().maxCoeff(), 1e-6);
}
}
int main(
int argc,
char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}