]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix MSVC compatibility
authorkwolekr <kwolekr@minetest.net>
Wed, 29 Apr 2015 17:20:01 +0000 (13:20 -0400)
committerkwolekr <kwolekr@minetest.net>
Wed, 29 Apr 2015 17:20:01 +0000 (13:20 -0400)
Make sure to include random unittests in android builds, too
Use SWAP() macro
Ensure that negative ranges are tested as well in random unittests

build/android/jni/Android.mk
src/mg_decoration.cpp
src/noise.cpp
src/unittest/test_random.cpp

index 000a0bfe5fc4c206e7528408bc5234afbe294687..c00d054b2e7cd6224beee431fa584abb608c53f3 100644 (file)
@@ -221,6 +221,7 @@ LOCAL_SRC_FILES :=                                \
                jni/src/unittest/test_nodedef.cpp         \
                jni/src/unittest/test_noise.cpp           \
                jni/src/unittest/test_profiler.cpp        \
+               jni/src/unittest/test_random.cpp          \
                jni/src/unittest/test_serialization.cpp   \
                jni/src/unittest/test_settings.cpp        \
                jni/src/unittest/test_socket.cpp          \
index 84f60b029f8a28609c77a86ef934086dfcc7f38e..460db1edea91a4d8e8065751eb12df9c1edc1607 100644 (file)
@@ -310,8 +310,7 @@ int DecoSimple::getHeight()
 ///////////////////////////////////////////////////////////////////////////////
 
 
-DecoSchematic::DecoSchematic() :
-       Decoration::Decoration()
+DecoSchematic::DecoSchematic()
 {
        schematic = NULL;
 }
index 614234aa4c52bbf9370fe86f85ecf4f63be3eff1..7a23819c8c9e121bda325f8d77e1b8edca6c2182 100644 (file)
@@ -148,7 +148,7 @@ s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
        s32 accum = 0;
        for (int i = 0; i != num_trials; i++)
                accum += range(min, max);
-       return round((float)accum / num_trials);
+       return myround((float)accum / num_trials);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 4f50bf9b887d8f68d38424fbf794a2adab6bede4..81cf9ae28051ecfe1b953d068eb2315e82e62d20 100644 (file)
@@ -74,13 +74,10 @@ void TestRandom::testPseudoRandomRange()
        EXCEPTION_CHECK(PrngException, pr.range(5, 1));
 
        for (u32 i = 0; i != 32768; i++) {
-               int min = pr.next() % 3000;
-               int max = pr.next() % 3000;
-               if (min > max) {
-                       int temp = min;
-                       min = max;
-                       max = temp;
-               }
+               int min = (pr.next() % 3000) - 500;
+               int max = (pr.next() % 3000) - 500;
+               if (min > max)
+                       SWAP(int, min, max);
 
                int randval = pr.range(min, max);
                UASSERT(randval >= min);
@@ -105,13 +102,10 @@ void TestRandom::testPcgRandomRange()
        EXCEPTION_CHECK(PrngException, pr.range(5, 1));
 
        for (u32 i = 0; i != 32768; i++) {
-               int min = pr.next() % 3000;
-               int max = pr.next() % 3000;
-               if (min > max) {
-                       int temp = min;
-                       min = max;
-                       max = temp;
-               }
+               int min = (pr.next() % 3000) - 500;
+               int max = (pr.next() % 3000) - 500;
+               if (min > max)
+                       SWAP(int, min, max);
 
                int randval = pr.range(min, max);
                UASSERT(randval >= min);
@@ -146,7 +140,7 @@ void TestRandom::testPcgRandomNormalDist()
        s32 bins[max - min + 1];
        memset(bins, 0, sizeof(bins));
 
-       PcgRandom r(486456179 + (int)time(NULL));
+       PcgRandom r(486179 + (int)time(NULL));
 
        for (u32 i = 0; i != num_samples; i++) {
                s32 randval = r.randNormalDist(min, max, num_trials);
@@ -173,8 +167,8 @@ void TestRandom::testPcgRandomNormalDist()
        //// Simple normality test using the 68-95-99.7% rule
        for (u32 i = 0; i != ARRLEN(prediction_intervals); i++) {
                float deviations = i / 2.f + 1.f;
-               int lbound = round(mean - deviations * stddev);
-               int ubound = round(mean + deviations * stddev);
+               int lbound = myround(mean - deviations * stddev);
+               int ubound = myround(mean + deviations * stddev);
                UASSERT(lbound >= min);
                UASSERT(ubound <= max);