diff options
author | Jaromir Wysoglad | 2019-04-02 12:38:17 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-04-06 15:02:58 +0300 |
commit | b070845a31410bae7b457201d63ec8b3b7c0e8e6 (patch) | |
tree | 5b3685ba288dabbde6774ef82214b038c746a68d /test | |
parent | 4a467cb1f88444cd94675ccde1d1d7a7359fba15 (diff) | |
download | scummvm-rg350-b070845a31410bae7b457201d63ec8b3b7c0e8e6.tar.gz scummvm-rg350-b070845a31410bae7b457201d63ec8b3b7c0e8e6.tar.bz2 scummvm-rg350-b070845a31410bae7b457201d63ec8b3b7c0e8e6.zip |
COMMON: add 2 tests for common/math.h
Diffstat (limited to 'test')
-rw-r--r-- | test/common/math.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/common/math.h b/test/common/math.h index 5da0410e8e..11d2b7e827 100644 --- a/test/common/math.h +++ b/test/common/math.h @@ -2,6 +2,14 @@ #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(((x) - (y)) >= 0 ? (x) - (y) : (y) - (x), z) + +const float PI = 3.141592653; +const float MAX_ERROR = 0.000001; class MathTestSuite : public CxxTest::TestSuite { public: @@ -15,4 +23,18 @@ class MathTestSuite : public CxxTest::TestSuite // Some simple test for 2^10 TS_ASSERT_EQUALS(Common::intLog2(1024), 10); } + + void test_rad2deg() { + TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(0), 0, MAX_ERROR); + TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(PI), 180.0, MAX_ERROR); + TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(2.0 * PI), 360.0, MAX_ERROR); + TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(PI / 2.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), PI, MAX_ERROR); + TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(360.0), 2.0 * PI, MAX_ERROR); + TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(90.0), PI / 2.0, MAX_ERROR); + } }; |