Skip to content

Commit

Permalink
Add reset() and configure() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Mar 7, 2022
1 parent 0c2c8ef commit b27ab71
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/unittests/test_derivative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
29 changes: 29 additions & 0 deletions test/unittests/test_integral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b27ab71

Please sign in to comment.