diff options
-rw-r--r-- | test/common/math.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/test/common/math.h b/test/common/math.h index 0d70264c73..5010ca5ed2 100644 --- a/test/common/math.h +++ b/test/common/math.h @@ -2,13 +2,7 @@ #include "common/math.h" -// Macro function for asserting that the compared values x and y -// aren't further apart from each other than z. - -#define TS_ASSERT_ALMOST_EQUALS(x, y, z) \ - TS_ASSERT_LESS_THAN_EQUALS(((x) - (y)) >= 0 ? (x) - (y) : (y) - (x), z) - -const float MAX_ERROR = 0.001; +const float MAX_ERROR = 1e-7; class MathTestSuite : public CxxTest::TestSuite { public: @@ -24,16 +18,28 @@ class MathTestSuite : public CxxTest::TestSuite } void test_rad2deg() { - TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(0), 0, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(M_PI), 180.0, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(2.0 * M_PI), 360.0, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(M_PI / 2.0), 90.0, MAX_ERROR); + //float verion + TS_ASSERT_DELTA(Common::rad2deg(0), 0, MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg(M_PI), 180.0, 180.0 * MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg(2.0 * M_PI), 360.0, 360.0 * MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg(M_PI / 2.0), 90.0, 90.0 * MAX_ERROR); + //double version + TS_ASSERT_DELTA(Common::rad2deg<double>(0), 0, MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg<double>(M_PI), 180.0, 180.0 * MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg<double>(2.0 * M_PI), 360.0, 360.0 * MAX_ERROR); + TS_ASSERT_DELTA(Common::rad2deg<double>(M_PI / 2.0), 90.0, 90.0 * MAX_ERROR); } void test_deg2rad() { - TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(0), 0, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(180.0), M_PI, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(360.0), 2.0 * M_PI, MAX_ERROR); - TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(90.0), M_PI / 2.0, MAX_ERROR); + //float verion + TS_ASSERT_DELTA(Common::deg2rad(0), 0, MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad(180.0), M_PI, M_PI * MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad(360.0), 2.0 * M_PI, 2.0 * M_PI * MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad(90.0), M_PI / 2.0, M_PI / 2.0 * MAX_ERROR); + //double version + TS_ASSERT_DELTA(Common::deg2rad<double>(0), 0, MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad<double>(180.0), M_PI, M_PI * MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad<double>(360.0), 2.0 * M_PI, 2.0 * M_PI * MAX_ERROR); + TS_ASSERT_DELTA(Common::deg2rad<double>(90.0), M_PI / 2.0, M_PI / 2.0 * MAX_ERROR); } }; |