aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_utilities.cpp
diff options
context:
space:
mode:
authorLoïc Blot <loic.blot@unix-experience.fr>2018-12-04 16:18:17 +0100
committerLoïc Blot <loic.blot@unix-experience.fr>2018-12-04 16:18:17 +0100
commit75a26b10abfdff4596584c057f05bceef76b55c7 (patch)
tree41aebb0d4c3690dd32f0ff7e02535cc79418f3a2 /src/unittest/test_utilities.cpp
parente6811184d5824bf7d8febc157495dbecd3e4e0f7 (diff)
downloadminetest-75a26b10abfdff4596584c057f05bceef76b55c7.tar.gz
minetest-75a26b10abfdff4596584c057f05bceef76b55c7.tar.bz2
minetest-75a26b10abfdff4596584c057f05bceef76b55c7.zip
Add testWrapDegrees_0_360_v3f unittests
Diffstat (limited to 'src/unittest/test_utilities.cpp')
-rw-r--r--src/unittest/test_utilities.cpp71
1 files changed, 56 insertions, 15 deletions
diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp
index 6f4a01432..112b53f0b 100644
--- a/src/unittest/test_utilities.cpp
+++ b/src/unittest/test_utilities.cpp
@@ -31,6 +31,7 @@ public:
void runTests(IGameDef *gamedef);
void testAngleWrapAround();
+ void testWrapDegrees_0_360_v3f();
void testLowercase();
void testTrim();
void testIsYes();
@@ -59,6 +60,7 @@ static TestUtilities g_test_instance;
void TestUtilities::runTests(IGameDef *gamedef)
{
TEST(testAngleWrapAround);
+ TEST(testWrapDegrees_0_360_v3f);
TEST(testLowercase);
TEST(testTrim);
TEST(testIsYes);
@@ -106,24 +108,63 @@ inline float ref_WrapDegrees_0_360(float f)
}
-void TestUtilities::testAngleWrapAround()
-{
- 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);
+void TestUtilities::testAngleWrapAround() {
+ 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(std::fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001);
- }
+ for (float f = -720; f <= -360; f += 0.25) {
+ UASSERT(std::fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001);
+ }
- for (float f = -1440; f <= 1440; f += 0.25) {
- UASSERT(std::fabs(modulo360f(f) - fmodf(f, 360)) < 0.001);
- UASSERT(std::fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001);
- UASSERT(std::fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001);
- UASSERT(wrapDegrees_0_360(
- std::fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001);
+ for (float f = -1440; f <= 1440; f += 0.25) {
+ UASSERT(std::fabs(modulo360f(f) - fmodf(f, 360)) < 0.001);
+ UASSERT(std::fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001);
+ UASSERT(std::fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001);
+ UASSERT(wrapDegrees_0_360(
+ std::fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001);
+ }
+
+}
+
+void TestUtilities::testWrapDegrees_0_360_v3f()
+{
+ // only x test with little step
+ for (float x = -720.f; x <= 720; x += 0.05) {
+ v3f r = wrapDegrees_0_360_v3f(v3f(x, 0, 0));
+ UASSERT(r.X >= 0.0f && r.X < 360.0f)
+ UASSERT(r.Y == 0.0f)
+ UASSERT(r.Z == 0.0f)
+ }
+
+ // only y test with little step
+ for (float y = -720.f; y <= 720; y += 0.05) {
+ v3f r = wrapDegrees_0_360_v3f(v3f(0, y, 0));
+ UASSERT(r.X == 0.0f)
+ UASSERT(r.Y >= 0.0f && r.Y < 360.0f)
+ UASSERT(r.Z == 0.0f)
+ }
+
+ // only z test with little step
+ for (float z = -720.f; z <= 720; z += 0.05) {
+ v3f r = wrapDegrees_0_360_v3f(v3f(0, 0, z));
+ UASSERT(r.X == 0.0f)
+ UASSERT(r.Y == 0.0f)
+ UASSERT(r.Z >= 0.0f && r.Z < 360.0f)
}
+
+ // test the whole coordinate translation
+ for (float x = -720.f; x <= 720; x += 2.5) {
+ for (float y = -720.f; y <= 720; y += 2.5) {
+ for (float z = -720.f; z <= 720; z += 2.5) {
+ v3f r = wrapDegrees_0_360_v3f(v3f(x, y, z));
+ UASSERT(r.X >= 0.0f && r.X < 360.0f)
+ UASSERT(r.Y >= 0.0f && r.Y < 360.0f)
+ UASSERT(r.Z >= 0.0f && r.Z < 360.0f)
+ }
+ }
+ }
}