new geo functions
changed the walkers added moving average fixed the interpolator new test-cases
This commit is contained in:
40
tests/math/TestInterpolator.cpp
Normal file
40
tests/math/TestInterpolator.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../Tests.h"
|
||||
#include "../../math/Interpolator.h"
|
||||
|
||||
TEST(Interpolator, addAndGet) {
|
||||
|
||||
Interpolator<int, float> interp;
|
||||
interp.add(10, 20);
|
||||
interp.add(20, 30);
|
||||
interp.add(30, 50);
|
||||
|
||||
ASSERT_EQ(20, std::round(interp.get(0))); // before
|
||||
ASSERT_EQ(20, std::round(interp.get(10))); // matches
|
||||
|
||||
ASSERT_EQ(21, std::round(interp.get(11)));
|
||||
ASSERT_EQ(25, std::round(interp.get(15)));
|
||||
ASSERT_EQ(29, std::round(interp.get(19)));
|
||||
|
||||
ASSERT_EQ(30, std::round(interp.get(20))); //matches
|
||||
|
||||
ASSERT_EQ(40, std::round(interp.get(25)));
|
||||
ASSERT_EQ(42, std::round(interp.get(26)));
|
||||
|
||||
ASSERT_EQ(50, std::round(interp.get(30))); // matches
|
||||
ASSERT_EQ(50, std::round(interp.get(99))); // after
|
||||
|
||||
}
|
||||
|
||||
TEST(Interpolator, sanity) {
|
||||
|
||||
Interpolator<int, int> interp;
|
||||
interp.add(10, 20);
|
||||
ASSERT_THROW( interp.add(10,30), std::exception );
|
||||
interp.add(12, 22);
|
||||
ASSERT_THROW( interp.add(11,21), std::exception );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
21
tests/math/TestMovingAVG.cpp
Normal file
21
tests/math/TestMovingAVG.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../Tests.h"
|
||||
#include "../../math/MovingAVG.h"
|
||||
|
||||
TEST(MovingAVG, add) {
|
||||
|
||||
MovingAVG<float> avg(3);
|
||||
|
||||
avg.add(1); ASSERT_EQ(1, avg.get());
|
||||
avg.add(1); ASSERT_EQ(1, avg.get());
|
||||
avg.add(1); ASSERT_EQ(1, avg.get());
|
||||
|
||||
avg.add(4); ASSERT_EQ(2, avg.get());
|
||||
avg.add(4); ASSERT_EQ(3, avg.get());
|
||||
|
||||
avg.add(4); ASSERT_EQ(4, avg.get());
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user