added random number generation algorithms
This commit is contained in:
@@ -10,9 +10,9 @@ void test_all(){
|
||||
test_hashtable();
|
||||
test_dtsod();
|
||||
test_kprint_colors();
|
||||
test_rng_algorithms();
|
||||
printf("\e[96m--------------------------------------\e[0m\n");
|
||||
}
|
||||
|
||||
int main(){
|
||||
setlocale(LC_ALL, "en-US.Unicode");
|
||||
ktDescriptors_beginInit();
|
||||
@@ -20,7 +20,8 @@ int main(){
|
||||
ktDescriptors_endInit();
|
||||
printf("\e[97mkerep tests are starting!\n");
|
||||
// optime("test_all",1,test_all());
|
||||
test_kprint_colors();
|
||||
// test_kprint_colors();
|
||||
test_rng_algorithms();
|
||||
printf("\e[0m\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
43
tests/test_rng_algorithms.c
Normal file
43
tests/test_rng_algorithms.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "tests.h"
|
||||
#include "../src/random/krandom.h"
|
||||
|
||||
|
||||
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\
|
||||
printf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
|
||||
ALG##_state s= ALG##_init(0);\
|
||||
uint##VALUE_SIZE r=ALG##_next(s);\
|
||||
printf("\e[97m next from zero seed:");\
|
||||
if(r!=EXPECTED_FROM_ZERO){\
|
||||
printf("\e[91m %llu\n", (uint64)r);\
|
||||
throw(ERR_UNEXPECTEDVAL);\
|
||||
}\
|
||||
printf("\e[92m %llu\n", (uint64)r);\
|
||||
s= ALG##_initFromTime();\
|
||||
r=ALG##_next(s);\
|
||||
printf("\e[97m next from time seed:\e[92m %llu\n", (uint64)r);\
|
||||
}
|
||||
|
||||
void test_rng_algorithms(){
|
||||
optime("test_rng_algorithms",1,({
|
||||
printf("\e[96m--------[test_rng_algorithms]---------\n");
|
||||
// for ALG32
|
||||
// xoroshiro64
|
||||
test_alg(xoroshiro64star, 32, 932574677ULL)
|
||||
test_alg(xoroshiro64starstar, 32, 3183060286ULL)
|
||||
// xoshiro128
|
||||
test_alg(xoshiro128plus, 32, 3918949401ULL)
|
||||
test_alg(xoshiro128plusplus, 32, 1179900579ULL)
|
||||
test_alg(xoshiro128starstar, 32, 3737715805ULL)
|
||||
// for ALG64
|
||||
// xoroshiro128
|
||||
test_alg(xoroshiro128plus, 64, 4778832803ULL)
|
||||
test_alg(xoroshiro128plusplus, 64, 626373238705583ULL)
|
||||
test_alg(xoroshiro128starstar, 64, 11897572417920ULL)
|
||||
// xoshiro256
|
||||
test_alg(xoshiro256plus, 64, 15757075719729598363ULL)
|
||||
test_alg(xoshiro256plusplus, 64, 5987356902031041503ULL)
|
||||
test_alg(xoshiro256starstar, 64, 11091344671253066420ULL)
|
||||
// splitmix64
|
||||
test_alg(splitmix64, 64, 16294208416658607535ULL)
|
||||
}));
|
||||
}
|
||||
@@ -15,6 +15,7 @@ void test_hashtable();
|
||||
void test_dtsod();
|
||||
void test_kprint_colors();
|
||||
void test_autoarrVsVector();
|
||||
void test_rng_algorithms();
|
||||
|
||||
#define PRINT_SIZEOF(T) printf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user