diff options
author | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-16 01:44:55 +0400 |
---|---|---|
committer | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-16 01:44:55 +0400 |
commit | 63f615c6c092fcc8c222e3906d4cc2796390da80 (patch) | |
tree | 1a5f0601a201dc6a164c4f230c41b31cd706e722 /source/test | |
parent | cfbefecf8f033c838aa7f325b400b2b949f81838 (diff) | |
download | kit-63f615c6c092fcc8c222e3906d4cc2796390da80.zip |
Mersenne Twister 64
Diffstat (limited to 'source/test')
-rw-r--r-- | source/test/unittests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/test/unittests/mersenne_twister_64.test.c | 33 |
2 files changed, 35 insertions, 1 deletions
diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt index 3dda690..5ec950d 100644 --- a/source/test/unittests/CMakeLists.txt +++ b/source/test/unittests/CMakeLists.txt @@ -3,4 +3,5 @@ target_sources( PRIVATE async_function.test.c test_duration.test.c main.test.c string_ref.test.c atomic.test.c array_ref.test.c input_stream.test.c - lower_bound.test.c input_buffer.test.c dynamic_array.test.c) + lower_bound.test.c mersenne_twister_64.test.c input_buffer.test.c + dynamic_array.test.c) diff --git a/source/test/unittests/mersenne_twister_64.test.c b/source/test/unittests/mersenne_twister_64.test.c new file mode 100644 index 0000000..37c82b4 --- /dev/null +++ b/source/test/unittests/mersenne_twister_64.test.c @@ -0,0 +1,33 @@ +#include "../../kit/mersenne_twister_64.h" + +#define TEST_FILE mersenne_twister_64 +#include "../../kit_test/test.h" + +enum { SIZE = 1000 }; + +TEST("mt64 same seeds") { + uint64_t seed = mt64_seed(); + + mt64_state_t foo, bar; + mt64_init(&foo, seed); + mt64_init(&bar, seed); + + int ok = 1; + for (ptrdiff_t i = 0; i < SIZE; i++) + ok = ok && mt64_generate(&foo) == mt64_generate(&bar); + + REQUIRE(ok); +} + +TEST("mt64 different seeds") { + mt64_state_t foo, bar; + mt64_init(&foo, 42); + mt64_init(&bar, 4242424242); + + ptrdiff_t difference_count = 0; + for (ptrdiff_t i = 0; i < SIZE; i++) + if (mt64_generate(&foo) != mt64_generate(&bar)) + difference_count++; + + REQUIRE(difference_count > SIZE / 2); +} |