From 63f615c6c092fcc8c222e3906d4cc2796390da80 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Tue, 16 Aug 2022 01:44:55 +0400 Subject: Mersenne Twister 64 --- source/test/unittests/CMakeLists.txt | 3 ++- source/test/unittests/mersenne_twister_64.test.c | 33 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 source/test/unittests/mersenne_twister_64.test.c (limited to 'source/test/unittests') 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); +} -- cgit v1.2.3