diff options
author | David Fioramonti | 2019-04-11 17:19:57 -0700 |
---|---|---|
committer | David Fioramonti | 2019-04-11 17:20:00 -0700 |
commit | 322af3e49ae800f45eae39e4f081197cba0b9a3f (patch) | |
tree | 41832f99c1c84b6fa90d03e1cb7ef217a04992ef /test | |
parent | cf0e9bfc1ba49726ef73acff028f74d97ee0e933 (diff) | |
download | scummvm-rg350-322af3e49ae800f45eae39e4f081197cba0b9a3f.tar.gz scummvm-rg350-322af3e49ae800f45eae39e4f081197cba0b9a3f.tar.bz2 scummvm-rg350-322af3e49ae800f45eae39e4f081197cba0b9a3f.zip |
TESTS: Use relative difference for math tests
Also add double template variants and use already defined delta
assert macro.
Diffstat (limited to 'test')
-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); } }; |