From b27ab719d15e7ccbd631cfca805d78936d83eb12 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Mon, 7 Mar 2022 11:12:24 +0100 Subject: [PATCH] Add reset() and configure() tests --- test/unittests/test_derivative.cpp | 11 +++++++++++ test/unittests/test_integral.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/test/unittests/test_derivative.cpp b/test/unittests/test_derivative.cpp index d98c7def..23f033e5 100644 --- a/test/unittests/test_derivative.cpp +++ b/test/unittests/test_derivative.cpp @@ -21,3 +21,14 @@ TEST(Derivative, StepResponse) EXPECT_NEAR(result, expected_response[i], eps); } } + +TEST(Derivative, Reset) +{ + double dt = 0.1; + + Derivative filter; + + EXPECT_NEAR(filter.filter(1, dt), 10, eps); + filter.reset(); + EXPECT_NEAR(filter.filter(0, dt), 0, eps); +} diff --git a/test/unittests/test_integral.cpp b/test/unittests/test_integral.cpp index 1510fcc7..1032cfc9 100644 --- a/test/unittests/test_integral.cpp +++ b/test/unittests/test_integral.cpp @@ -22,3 +22,32 @@ TEST(Integral, StepResponse) EXPECT_NEAR(result, expected_response[i], eps); } } + +TEST(Integral, Reset) +{ + double dt = 0.1; + double windup_limit = 0.5; + + Integral filter{windup_limit}; + + EXPECT_NEAR(filter.filter(1, dt), 0.05, eps); + EXPECT_NEAR(filter.filter(1, dt), 0.15, eps); + filter.reset(); + EXPECT_NEAR(filter.filter(1, dt), 0.05, eps); + EXPECT_NEAR(filter.filter(1, dt), 0.15, eps); +} + +TEST(Integral, Configure) +{ + double dt = 0.1; + double windup_limit = 0.2; + + Integral filter{windup_limit}; + + EXPECT_NEAR(filter.filter(1, dt), 0.05, eps); + EXPECT_NEAR(filter.filter(1, dt), 0.15, eps); + EXPECT_NEAR(filter.filter(1, dt), 0.20, eps); + filter.configure(0.35); + EXPECT_NEAR(filter.filter(1, dt), 0.30, eps); + EXPECT_NEAR(filter.filter(1, dt), 0.35, eps); +}