adjusted code and test-cases for fixed-freq-interpolater
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
#include "../Tests.h"
|
||||
#include "../../math/FixedFrequencyInterpolator.h"
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
|
||||
TEST(FixedFrequencyInterpolator, test) {
|
||||
/*
|
||||
TEST(FixedFrequencyInterpolator, testOLD) {
|
||||
|
||||
FixedFrequencyInterpolator<float> ffi(Timestamp::fromMS(10));
|
||||
|
||||
@@ -55,7 +57,74 @@ TEST(FixedFrequencyInterpolator, test) {
|
||||
ASSERT_NEAR(data[18], x*240, d);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
TEST(FixedFrequencyInterpolator, testNEW) {
|
||||
|
||||
FixedFrequencyInterpolator<float> ffi(Timestamp::fromMS(9));
|
||||
|
||||
// randomly draw points along a line using random intervals
|
||||
Timestamp pos;
|
||||
std::minstd_rand gen;
|
||||
std::uniform_int_distribution<int> dist(2, 65);
|
||||
auto func = [] (const Timestamp ts) {
|
||||
return 0.5 * ts.ms() + 12;
|
||||
};
|
||||
|
||||
// compare the randomly drawn points against interpolated fixed-frequency interpolated versions
|
||||
auto cb = [&] (const Timestamp ts, const float val) {
|
||||
ASSERT_NEAR(val, func(ts), 0.001); // interpolated vs original position on line
|
||||
};
|
||||
|
||||
// run
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
const float y = func(pos);
|
||||
ffi.add(pos, y, cb);
|
||||
pos += Timestamp::fromMS(dist(gen));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(FixedFrequencyInterpolator, testUpsample) {
|
||||
|
||||
FixedFrequencyInterpolator<float> ffi(Timestamp::fromMS(10));
|
||||
int cnt = 0;
|
||||
|
||||
auto cb = [&] (const Timestamp ts, const float f) {
|
||||
if (cnt == 0) {ASSERT_EQ(ts.ms(), 0); ASSERT_NEAR( 0, f, 0.001);}
|
||||
if (cnt == 1) {ASSERT_EQ(ts.ms(), 10); ASSERT_NEAR( 10, f, 0.001);}
|
||||
if (cnt == 10) {ASSERT_EQ(ts.ms(),100); ASSERT_NEAR(100, f, 0.001);}
|
||||
++cnt;
|
||||
};
|
||||
|
||||
// add two entries. one at t=0 one at t=100. must be up-sampled into 11 entries (t=0, t=10, t=100)
|
||||
ffi.add(Timestamp::fromMS(0), 0, cb);
|
||||
ffi.add(Timestamp::fromMS(101), 101, cb);
|
||||
ASSERT_EQ(11, cnt);
|
||||
|
||||
}
|
||||
|
||||
TEST(FixedFrequencyInterpolator, testDownsample) {
|
||||
|
||||
FixedFrequencyInterpolator<float> ffi(Timestamp::fromMS(50));
|
||||
int cnt = 0;
|
||||
|
||||
auto cb = [&] (const Timestamp ts, const float f) {
|
||||
if (cnt == 0) {ASSERT_EQ(ts.ms(), 0); ASSERT_NEAR( 0, f, 0.001);}
|
||||
if (cnt == 1) {ASSERT_EQ(ts.ms(), 50); ASSERT_NEAR( 50, f, 0.001);}
|
||||
if (cnt == 2) {ASSERT_EQ(ts.ms(), 100); ASSERT_NEAR(100, f, 0.001);}
|
||||
++cnt;
|
||||
};
|
||||
|
||||
// add 100+ entries in 1 ms steps. must be downsampled to 3 entries (t=0, t=50, t=100)
|
||||
for (int i = 0; i <= 101; ++i) {
|
||||
ffi.add(Timestamp::fromMS(i), i, cb);
|
||||
}
|
||||
ASSERT_EQ(3, cnt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user