From c93f0a71e1ed68e658f9f190bb75db28566da38d Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Sun, 25 Jan 2015 01:24:57 +0100 Subject: [PATCH] Adding unit tests for constrain wih negative values since the constrain method takes signed arguments. --- src/test/unit/maths_unittest.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/unit/maths_unittest.cc b/src/test/unit/maths_unittest.cc index 0b341671f..429f2396d 100644 --- a/src/test/unit/maths_unittest.cc +++ b/src/test/unit/maths_unittest.cc @@ -31,7 +31,9 @@ extern "C" { TEST(MathsUnittest, TestConstrain) { - // Within bounds. + // Within bounds + EXPECT_EQ(constrain(0, 0, 0), 0); + EXPECT_EQ(constrain(1, 1, 1), 1); EXPECT_EQ(constrain(1, 0, 2), 1); // Equal to bottom bound. @@ -46,11 +48,26 @@ TEST(MathsUnittest, TestConstrain) EXPECT_EQ(constrain(2, 0, 1), 1); // Below bottom bound. EXPECT_EQ(constrain(0, 1, 2), 1); +} - // Above bouth bounds. - EXPECT_EQ(constrain(2, 0, 1), 1); - // Below bouth bounds. - EXPECT_EQ(constrain(0, 1, 2), 1); +TEST(MathsUnittest, TestConstrainNegatives) +{ + // Within bounds. + EXPECT_EQ(constrain(-1, -1, -1), -1); + EXPECT_EQ(constrain(-1, -2, 0), -1); + + // Equal to bottom bound. + EXPECT_EQ(constrain(-1, -1, 0), -1); + // Equal to top bound. + EXPECT_EQ(constrain(-1, -2, -1), -1); + + // Equal to both bottom and top bound. + EXPECT_EQ(constrain(-1, -1, -1), -1); + + // Above top bound. + EXPECT_EQ(constrain(-1, -3, -2), -2); + // Below bottom bound. + EXPECT_EQ(constrain(-3, -2, -1), -2); } TEST(MathsUnittest, TestConstrainf) -- 2.11.4.GIT