kerep/tests/test_rng_algorithms.c

43 lines
1.6 KiB
C

#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)
}));
}