Skip to content

Commit

Permalink
added test for filter::MovingAverage::reset(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Jun 7, 2022
1 parent 9568d68 commit bc038af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/modm/math/filter/moving_average_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ MovingAverageTest::testAverage()
}
}

void
MovingAverageTest::testReset()
{
modm::filter::MovingAverage<TestData::Type, 4> filter;

for (uint_fast8_t i = 0; i < 4; ++i)
{
filter.update(data[i].input);
}

filter.reset(42);
TEST_ASSERT_EQUALS(filter.getValue(), 42);
}

void
MovingAverageTest::testFloatAverage()
{
Expand All @@ -117,3 +131,17 @@ MovingAverageTest::testFloatAverage()
TEST_ASSERT_EQUALS_DELTA(filter.getValue(), dataF[i].output, double(1e-4));
}
}

void
MovingAverageTest::testFloatReset()
{
modm::filter::MovingAverage<TestDataFloat::Type, 4> filter;

for (uint_fast8_t i = 0; i < 4; ++i)
{
filter.update(dataF[i].input);
}

filter.reset(42.23);
TEST_ASSERT_EQUALS(filter.getValue(), 42.23);
}
6 changes: 6 additions & 0 deletions test/modm/math/filter/moving_average_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class MovingAverageTest : public unittest::TestSuite
void
testAverage();

void
testReset();

void
testFloatAverage();

void
testFloatReset();
};

0 comments on commit bc038af

Please sign in to comment.