From dd0e34346c18ad199e22976c657a787906f7df1f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 24 Oct 2023 01:03:02 -0700 Subject: [PATCH] unit test for wrapAngle --- unit_tests/tests/test_util.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/unit_tests/tests/test_util.cpp b/unit_tests/tests/test_util.cpp index a7a2947d6d..d000de0ddb 100644 --- a/unit_tests/tests/test_util.cpp +++ b/unit_tests/tests/test_util.cpp @@ -431,3 +431,24 @@ TEST(util, isInRange) { EXPECT_TRUE(isInRange(5, 10, 10)); EXPECT_FALSE(isInRange(5, 11, 10)); } + +TEST(util, wrapAngle) { + EngineTestHelper eth(engine_type_e::TEST_ENGINE); + + // Test within range + EXPECT_EQ(0, wrapAngleMethod(0)); + EXPECT_EQ(20, wrapAngleMethod(20)); + EXPECT_EQ(710, wrapAngleMethod(710)); + + // Test off the top of the range + EXPECT_EQ(1, wrapAngleMethod(721)); + EXPECT_EQ(20, wrapAngleMethod(740)); + EXPECT_EQ(719, wrapAngleMethod(720 + 719)); + EXPECT_EQ(0, wrapAngleMethod(720 + 720)); + EXPECT_EQ(5, wrapAngleMethod(10 * 720 + 5)); + + // Test off the bottom of the range + EXPECT_EQ(719, wrapAngleMethod(-1)); + EXPECT_EQ(360, wrapAngleMethod(-360)); + EXPECT_EQ(1, wrapAngleMethod(-719)); +}