|
@@ -1,95 +1,99 @@
|
|
|
-#include "../Tests.h"
|
|
|
-#include "core/Random.h"
|
|
|
+#include "../Tests.hpp"
|
|
|
+#include "core/Random.hpp"
|
|
|
+#include "core/Test.hpp"
|
|
|
+
|
|
|
+using Core::Random;
|
|
|
|
|
|
static void testAverage(bool light) {
|
|
|
int limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 553);
|
|
|
+ Random r(553);
|
|
|
float sum = 0;
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- u32 u = randomU32(&r, 2, 11);
|
|
|
- sum += (float)u;
|
|
|
+ sum += static_cast<float>(r.nextU32(2, 11));
|
|
|
}
|
|
|
- sum /= (float)limit;
|
|
|
+ sum /= static_cast<float>(limit);
|
|
|
TEST_FLOAT(6.0f, sum, 0.01f);
|
|
|
}
|
|
|
|
|
|
static void testCoin(bool light) {
|
|
|
int limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 5533);
|
|
|
+ Random r(5533);
|
|
|
int c[2] = {0, 0};
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- c[randomBool(&r)]++;
|
|
|
+ c[r.nextBool()]++;
|
|
|
}
|
|
|
- TEST_FLOAT(0.0f, (float)(c[0] - c[1]) / (float)limit, 0.003f);
|
|
|
+ TEST_FLOAT(
|
|
|
+ 0.0f, static_cast<float>(c[0] - c[1]) / static_cast<float>(limit),
|
|
|
+ 0.003f);
|
|
|
}
|
|
|
|
|
|
static void testDistribution(bool light) {
|
|
|
size_t limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 553);
|
|
|
- int c[102] = {0};
|
|
|
+ Random r(553);
|
|
|
+ Core::Array<int, 102> c(0);
|
|
|
for(size_t i = 0; i < limit; i++) {
|
|
|
- c[randomSize(&r, 1, 101)]++;
|
|
|
+ c[r.nextSize(1, c.getLength() - 1)]++;
|
|
|
}
|
|
|
- TEST_INT(0, c[0]);
|
|
|
- TEST_INT(0, c[101]);
|
|
|
- for(size_t i = 1; i < 101; i++) {
|
|
|
- TEST_FLOAT(0.01f, (float)c[i] / (float)limit, 0.001f);
|
|
|
+ TEST(0, c[0]);
|
|
|
+ TEST(0, c[c.getLength() - 1]);
|
|
|
+ for(size_t i = 1; i < c.getLength() - 1; i++) {
|
|
|
+ TEST_FLOAT(
|
|
|
+ 0.01f, static_cast<float>(c[i]) / static_cast<float>(limit),
|
|
|
+ 0.001f);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void testFloatAverage(bool light) {
|
|
|
int limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 553);
|
|
|
+ Core::Random r(553);
|
|
|
float sum = 0;
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- sum += randomFloat(&r);
|
|
|
+ sum += r.nextFloat();
|
|
|
}
|
|
|
- sum /= (float)limit;
|
|
|
+ sum /= static_cast<float>(limit);
|
|
|
TEST_FLOAT(0.5f, sum, 0.001f);
|
|
|
}
|
|
|
|
|
|
static void testFloatCoin(bool light) {
|
|
|
int limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 5534);
|
|
|
- int c[2] = {0, 0};
|
|
|
+ Random r(5535);
|
|
|
+ Core::Array<int, 2> c(0);
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- c[randomFloat(&r) < 0.5f]++;
|
|
|
+ c[r.nextFloat() < 0.5f]++;
|
|
|
}
|
|
|
- TEST_FLOAT(0.0f, (float)(c[0] - c[1]) / (float)limit, 0.003f);
|
|
|
+ TEST_FLOAT(
|
|
|
+ 0.0f, static_cast<float>(c[0] - c[1]) / static_cast<float>(limit),
|
|
|
+ 0.003f);
|
|
|
}
|
|
|
|
|
|
static void testFloatDistribution(bool light) {
|
|
|
int limit = light ? 100'000 : 1'000'000;
|
|
|
- Random r;
|
|
|
- initRandom(&r, 553);
|
|
|
- int c[102] = {0};
|
|
|
+ Random r(553);
|
|
|
+ Core::Array<int, 102> c(0);
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- c[(size_t)(1.0f + randomFloat(&r) * 100.0f)]++;
|
|
|
+ c[static_cast<size_t>(1.0f + r.nextFloat() * (c.getLength() - 2))]++;
|
|
|
}
|
|
|
- TEST_INT(0, c[0]);
|
|
|
- TEST_INT(0, c[101]);
|
|
|
- for(size_t i = 1; i < 101; i++) {
|
|
|
- TEST_FLOAT(0.01f, (float)c[i] / (float)limit, 0.003f);
|
|
|
+ TEST(0, c[0]);
|
|
|
+ TEST(0, c[c.getLength() - 1]);
|
|
|
+ for(size_t i = 1; i < c.getLength() - 1; i++) {
|
|
|
+ TEST_FLOAT(
|
|
|
+ 0.01f, static_cast<float>(c[i]) / static_cast<float>(limit),
|
|
|
+ 0.003f);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void testRandomI32() {
|
|
|
- Random r;
|
|
|
- initRandom(&r, 56'346);
|
|
|
- int c[7] = {0};
|
|
|
+ Random r(56'346);
|
|
|
+ Core::Array<int, 7> c;
|
|
|
+ c.fill(0);
|
|
|
for(int i = 0; i < 10'000; i++) {
|
|
|
- i32 index = randomI32(&r, -2, 3) + 3;
|
|
|
- if(TEST_TRUE(index >= 0 && index < 7)) {
|
|
|
- c[index]++;
|
|
|
+ i32 index = r.nextI32(-2, 3) + 3;
|
|
|
+ if(TEST_TRUE(index >= 0)) {
|
|
|
+ c[static_cast<size_t>(index)]++;
|
|
|
}
|
|
|
}
|
|
|
- for(size_t i = 0; i < 7; i++) {
|
|
|
- TEST_BOOL(i != 0 && i != 6, c[i] > 0);
|
|
|
+ for(size_t i = 0; i < c.getLength(); i++) {
|
|
|
+ TEST(i != 0 && i != c.getLength() - 1, c[i] > 0);
|
|
|
}
|
|
|
}
|
|
|
|