summaryrefslogtreecommitdiff
path: root/source/test/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'source/test/unittests')
-rw-r--r--source/test/unittests/CMakeLists.txt3
-rw-r--r--source/test/unittests/mersenne_twister_64.test.c33
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);
+}