diff options
author | Craig Robbins <kde.psych@gmail.com> | 2015-02-23 16:25:14 +1000 |
---|---|---|
committer | Craig Robbins <kde.psych@gmail.com> | 2015-02-23 22:50:32 +1000 |
commit | 3b6480c5b0c968ad9f5a7cfb7ca494989be03629 (patch) | |
tree | 1d8acc30b33c652a2d7897ed5f89b3825888bd43 /src/test.cpp | |
parent | 51057a56f540f4e74b424e22c94357e5cb5268b2 (diff) | |
download | minetest-3b6480c5b0c968ad9f5a7cfb7ca494989be03629.tar.gz minetest-3b6480c5b0c968ad9f5a7cfb7ca494989be03629.tar.bz2 minetest-3b6480c5b0c968ad9f5a7cfb7ca494989be03629.zip |
Fix wrapDegrees family of functions
wrapDegrees() (renamed to modulo360f)
wrapDegrees_0_360
wrapDegrees_180
Minor errors were present in previous versions; see issue #2328
Diffstat (limited to 'src/test.cpp')
-rw-r--r-- | src/test.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/test.cpp b/src/test.cpp index 3b7c75c6e..350cab127 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -147,15 +147,45 @@ struct TestBase struct TestUtilities: public TestBase { + inline float ref_WrapDegrees180(float f) + { + // This is a slower alternative to the wrapDegrees_180() function; + // used as a reference for testing + float value = fmodf(f + 180, 360); + if (value < 0) + value += 360; + return value - 180; + } + + inline float ref_WrapDegrees_0_360(float f) + { + // This is a slower alternative to the wrapDegrees_0_360() function; + // used as a reference for testing + float value = fmodf(f, 360); + if (value < 0) + value += 360; + return value < 0 ? value + 360 : value; + } + + void Run() { - /*infostream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl; - infostream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl; - infostream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/ - UASSERT(fabs(wrapDegrees(100.0) - 100.0) < 0.001); - UASSERT(fabs(wrapDegrees(720.5) - 0.5) < 0.001); - UASSERT(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001); - UASSERT(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001); + UASSERT(fabs(modulo360f(100.0) - 100.0) < 0.001); + UASSERT(fabs(modulo360f(720.5) - 0.5) < 0.001); + UASSERT(fabs(modulo360f(-0.5) - (-0.5)) < 0.001); + UASSERT(fabs(modulo360f(-365.5) - (-5.5)) < 0.001); + + for (float f = -720; f <= -360; f += 0.25) { + UASSERT(fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001); + } + + for (float f = -1440; f <= 1440; f += 0.25) { + UASSERT(fabs(modulo360f(f) - fmodf(f, 360)) < 0.001); + UASSERT(fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001); + UASSERT(fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001); + UASSERT(wrapDegrees_0_360(fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001); + } + UASSERT(lowercase("Foo bAR") == "foo bar"); UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR"); UASSERT(trim("\n \t\r \r\n\t\t ") == ""); |