stdlib: add a test for TinyMT random numbers
This commit is contained in:
parent
d5d3c791f3
commit
684f827e99
|
@ -41,6 +41,7 @@ set(SOURCES
|
|||
src/stdlib/exit.c
|
||||
src/stdlib/fpconv.c
|
||||
src/stdlib/intconv.c
|
||||
src/stdlib/rand.c
|
||||
src/stdlib/sizes.c
|
||||
# string
|
||||
src/string/core.c
|
||||
|
|
|
@ -34,6 +34,7 @@ extern ft_test ft_stdlib_sizes;
|
|||
extern ft_test ft_stdlib_llconv;
|
||||
extern ft_test ft_stdlib_lconv;
|
||||
extern ft_test ft_stdlib_fpconv;
|
||||
extern ft_test ft_stdlib_rand;
|
||||
extern ft_test ft_stdlib_exit;
|
||||
extern ft_test ft_stdlib__Exit;
|
||||
extern ft_test ft_stdlib_abort;
|
||||
|
|
|
@ -51,6 +51,7 @@ ft_list headers_libc[] = {
|
|||
&ft_stdlib_llconv,
|
||||
&ft_stdlib_lconv,
|
||||
&ft_stdlib_fpconv,
|
||||
&ft_stdlib_rand,
|
||||
&ft_stdlib_exit,
|
||||
&ft_stdlib__Exit,
|
||||
&ft_stdlib_abort,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#include <ft/test.h>
|
||||
#include <ft/all-tests.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void _ft_stdlib_rand(ft_test *t)
|
||||
{
|
||||
srand(0xdeadbeef);
|
||||
ft_assert(t, rand() == 0x797dd849);
|
||||
ft_assert(t, rand() == 0x02687112);
|
||||
ft_assert(t, rand() == 0x2222a00d);
|
||||
ft_assert(t, rand() == 0x67c2ff94);
|
||||
|
||||
unsigned int seed = 0xc0ffee;
|
||||
srand(seed);
|
||||
ft_log(t, "Seed: %#x\n\n", seed);
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
int i1 = rand();
|
||||
int i2 = rand();
|
||||
int i3 = rand();
|
||||
int i4 = rand();
|
||||
|
||||
ft_log(t, " %08X %08X %08X %08X\n", i1, i2, i3, i4);
|
||||
}
|
||||
}
|
||||
|
||||
ft_test ft_stdlib_rand = {
|
||||
.name = "TinyMT random numbers",
|
||||
.function = _ft_stdlib_rand,
|
||||
};
|
Loading…
Reference in New Issue