aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-04-02 23:51:08 +0200
committerGitHub <noreply@github.com>2018-04-02 23:51:08 +0200
commit2481ea27ce0f423f3e6f3522539d20e1500cf572 (patch)
tree73251dcbf9146d7499177f59b266d8c60b0eaae7 /src/unittest
parente98fd934ce17a7af0b4629fc88158373303c88a0 (diff)
downloadminetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.tar.gz
minetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.tar.bz2
minetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.zip
Fix many issues reported by clang-tidy (#7189)
* Fix many issues reported by clang-tidy We have many issues in code related to some performance to float <-> double. Clang-tidy reported it in performance-type-promotion-in-math-fn I fixed many of them. It's not ready for a promote to blocking Also fix some value which should be const-ref
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test_noise.cpp9
-rw-r--r--src/unittest/test_random.cpp5
-rw-r--r--src/unittest/test_settings.cpp13
-rw-r--r--src/unittest/test_utilities.cpp9
4 files changed, 20 insertions, 16 deletions
diff --git a/src/unittest/test_noise.cpp b/src/unittest/test_noise.cpp
index 988ea4495..421f3b66e 100644
--- a/src/unittest/test_noise.cpp
+++ b/src/unittest/test_noise.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "test.h"
+#include <cmath>
#include "exceptions.h"
#include "noise.h"
@@ -61,7 +62,7 @@ void TestNoise::testNoise2dPoint()
for (u32 x = 0; x != 10; x++, i++) {
float actual = NoisePerlin2D(&np_normal, x, y, 1337);
float expected = expected_2d_results[i];
- UASSERT(fabs(actual - expected) <= 0.00001);
+ UASSERT(std::fabs(actual - expected) <= 0.00001);
}
}
@@ -74,7 +75,7 @@ void TestNoise::testNoise2dBulk()
for (u32 i = 0; i != 10 * 10; i++) {
float actual = noisevals[i];
float expected = expected_2d_results[i];
- UASSERT(fabs(actual - expected) <= 0.00001);
+ UASSERT(std::fabs(actual - expected) <= 0.00001);
}
}
@@ -88,7 +89,7 @@ void TestNoise::testNoise3dPoint()
for (u32 x = 0; x != 10; x++, i++) {
float actual = NoisePerlin3D(&np_normal, x, y, z, 1337);
float expected = expected_3d_results[i];
- UASSERT(fabs(actual - expected) <= 0.00001);
+ UASSERT(std::fabs(actual - expected) <= 0.00001);
}
}
@@ -101,7 +102,7 @@ void TestNoise::testNoise3dBulk()
for (u32 i = 0; i != 10 * 10 * 10; i++) {
float actual = noisevals[i];
float expected = expected_3d_results[i];
- UASSERT(fabs(actual - expected) <= 0.00001);
+ UASSERT(std::fabs(actual - expected) <= 0.00001);
}
}
diff --git a/src/unittest/test_random.cpp b/src/unittest/test_random.cpp
index bbee57719..14de764e1 100644
--- a/src/unittest/test_random.cpp
+++ b/src/unittest/test_random.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "test.h"
+#include <cmath>
#include "util/numeric.h"
#include "exceptions.h"
#include "noise.h"
@@ -157,7 +158,7 @@ void TestRandom::testPcgRandomNormalDist()
int range = (max - min + 1);
float mean = (max + min) / 2;
float variance = ((range * range - 1) / 12) / num_trials;
- float stddev = sqrt(variance);
+ float stddev = std::sqrt(variance);
static const float prediction_intervals[] = {
0.68269f, // 1.0
@@ -180,7 +181,7 @@ void TestRandom::testPcgRandomNormalDist()
accum += bins[j - min];
float actual = (float)accum / num_samples;
- UASSERT(fabs(actual - prediction_intervals[i]) < 0.02);
+ UASSERT(std::fabs(actual - prediction_intervals[i]) < 0.02f);
}
}
diff --git a/src/unittest/test_settings.cpp b/src/unittest/test_settings.cpp
index 733c7e92a..b2666559e 100644
--- a/src/unittest/test_settings.cpp
+++ b/src/unittest/test_settings.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "test.h"
+#include <cmath>
#include "settings.h"
#include "noise.h"
@@ -174,14 +175,14 @@ void TestSettings::testAllSettings()
NoiseParams np;
UASSERT(s.getNoiseParams("np_terrain", np) == true);
- UASSERT(fabs(np.offset - 5) < 0.001);
- UASSERT(fabs(np.scale - 40) < 0.001);
- UASSERT(fabs(np.spread.X - 250) < 0.001);
- UASSERT(fabs(np.spread.Y - 250) < 0.001);
- UASSERT(fabs(np.spread.Z - 250) < 0.001);
+ UASSERT(std::fabs(np.offset - 5) < 0.001f);
+ UASSERT(std::fabs(np.scale - 40) < 0.001f);
+ UASSERT(std::fabs(np.spread.X - 250) < 0.001f);
+ UASSERT(std::fabs(np.spread.Y - 250) < 0.001f);
+ UASSERT(std::fabs(np.spread.Z - 250) < 0.001f);
UASSERT(np.seed == 12341);
UASSERT(np.octaves == 5);
- UASSERT(fabs(np.persist - 0.7) < 0.001);
+ UASSERT(std::fabs(np.persist - 0.7) < 0.001f);
np.offset = 3.5;
np.octaves = 6;
diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp
index d73975b9f..95c34a9c7 100644
--- a/src/unittest/test_utilities.cpp
+++ b/src/unittest/test_utilities.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "test.h"
+#include <cmath>
#include "util/numeric.h"
#include "util/string.h"
@@ -111,13 +112,13 @@ void TestUtilities::testAngleWrapAround()
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);
+ UASSERT(std::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(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(fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001);
}
}