From 0a8cccd79aacd4aef4d1a2fcc4e9826f8ef14490 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 18 Feb 2022 09:27:06 +1100 Subject: [PATCH] Filter: add test for AverageIntegralFilter --- libraries/Filter/tests/test_averagefilter.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libraries/Filter/tests/test_averagefilter.cpp b/libraries/Filter/tests/test_averagefilter.cpp index c6511d91b2..ddae67ce7d 100644 --- a/libraries/Filter/tests/test_averagefilter.cpp +++ b/libraries/Filter/tests/test_averagefilter.cpp @@ -42,4 +42,31 @@ TEST(AverageFilterTest, Float_Size5) } +TEST(AverageIntegralFilterTest, UInt16_Size5) +{ + AverageIntegralFilter test_filter; + // filter should be zero even on stack (this may not pick up bugs, but may): + EXPECT_FLOAT_EQ(0, test_filter.getf()); + EXPECT_FLOAT_EQ(0, test_filter.getd()); + + EXPECT_EQ(0, test_filter.apply(1)); // apply always returns 0 + EXPECT_FLOAT_EQ(1, test_filter.getf()); + + EXPECT_EQ(0, test_filter.apply(3)); // apply always returns 0 + EXPECT_FLOAT_EQ(2, test_filter.getf()); + + EXPECT_EQ(0, test_filter.apply(2)); // apply always returns 0 + EXPECT_FLOAT_EQ(2, test_filter.getf()); + + EXPECT_EQ(0, test_filter.apply(4)); // apply always returns 0 + EXPECT_FLOAT_EQ(2.5, test_filter.getf()); + + EXPECT_EQ(0, test_filter.apply(100)); // apply always returns 0 + EXPECT_FLOAT_EQ(22, test_filter.getf()); + + EXPECT_EQ(0, test_filter.apply(110)); // apply always returns 0 + EXPECT_FLOAT_EQ(43.799999, test_filter.getf()); + EXPECT_FLOAT_EQ(43.799999, test_filter.getd()); +} + AP_GTEST_MAIN()