diff options
author | kwolekr <kwolekr@minetest.net> | 2015-04-29 13:20:01 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-04-29 13:20:01 -0400 |
commit | 37ca3212eee6d70a54493168014f9254cc6e8f37 (patch) | |
tree | c2589b164fb280efa27832c4d3cfc8655c2b2ea7 /src/unittest | |
parent | b6475f54487690e23cf9541a68f98649edb8f0e0 (diff) | |
download | minetest-37ca3212eee6d70a54493168014f9254cc6e8f37.tar.gz minetest-37ca3212eee6d70a54493168014f9254cc6e8f37.tar.bz2 minetest-37ca3212eee6d70a54493168014f9254cc6e8f37.zip |
Fix MSVC compatibility
Make sure to include random unittests in android builds, too
Use SWAP() macro
Ensure that negative ranges are tested as well in random unittests
Diffstat (limited to 'src/unittest')
-rw-r--r-- | src/unittest/test_random.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/unittest/test_random.cpp b/src/unittest/test_random.cpp index 4f50bf9b8..81cf9ae28 100644 --- a/src/unittest/test_random.cpp +++ b/src/unittest/test_random.cpp @@ -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); |