diff options
author | Mattes D <github@xoft.cz> | 2017-03-28 16:37:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-28 16:37:25 +0200 |
commit | 5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69 (patch) | |
tree | 9dbb0087fe80f2bff8da8d9eb9847acfd9cc0638 | |
parent | Merge pull request #3641 from cuberite/firework_nbt (diff) | |
download | cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar.gz cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar.bz2 cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar.lz cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar.xz cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.tar.zst cuberite-5dc0189a160a9ab4d6c9c2865fc8ff5d7ca32d69.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/FastRandom/FastRandomTest.cpp | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/tests/FastRandom/FastRandomTest.cpp b/tests/FastRandom/FastRandomTest.cpp index e7729382d..9ab775936 100644 --- a/tests/FastRandom/FastRandomTest.cpp +++ b/tests/FastRandom/FastRandomTest.cpp @@ -7,6 +7,9 @@ #include "FastRandom.h" + + + static void TestInts(void) { cFastRandom rnd; @@ -24,14 +27,17 @@ static void TestInts(void) sum += v; } double avg = static_cast<double>(sum) / ITER; - printf("avg: %f\n", avg); + LOG("avg: %f", avg); for (int i = 0; i < BUCKETS; i++) { - printf(" bucket %d: %d\n", i, Counts[i]); + LOG(" bucket %d: %d", i, Counts[i]); } } + + + static void TestFloats(void) { cFastRandom rnd; @@ -49,23 +55,65 @@ static void TestFloats(void) sum += v; } sum = sum / ITER; - printf("avg: %f\n", sum); + LOG("avg: %f", sum); for (int i = 0; i < BUCKETS; i++) { - printf(" bucket %d: %d\n", i, Counts[i]); + LOG(" bucket %d: %d", i, Counts[i]); + } +} + + + + + +/** Checks whether re-creating the cFastRandom class produces the same initial number over and over (#2935) */ +static void TestReCreation(void) +{ + const int ITER = 10000; + int lastVal = 0; + int numSame = 0; + int maxNumSame = 0; + for (int i = 0; i < ITER; ++i) + { + cFastRandom rnd; + int val = rnd.NextInt(10); + if (val == lastVal) + { + numSame += 1; + } + else + { + if (numSame > maxNumSame) + { + maxNumSame = numSame; + } + numSame = 0; + lastVal = val; + } } + if (numSame > maxNumSame) + { + maxNumSame = numSame; + } + LOG("Out of %d creations, there was a chain of at most %d same numbers generated.", ITER, maxNumSame); } + + + int main(void) { - LOGD("FastRandom Test started"); + LOG("FastRandom Test started"); - LOGD("Testing ints"); + LOG("Testing ints"); TestInts(); - LOGD("Testing floats"); + LOG("Testing floats"); TestFloats(); + LOG("Testing re-creation"); + TestReCreation(); + LOG("FastRandom test finished"); } |