From 98a835c8293236d5b60e684ef646e6ad6eab8acb Mon Sep 17 00:00:00 2001 From: revsic Date: Sun, 7 Apr 2019 01:52:22 +0900 Subject: [PATCH] obfs, test: Add tests for random --- test/impl/random.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/impl/random.cpp diff --git a/test/impl/random.cpp b/test/impl/random.cpp new file mode 100644 index 0000000..35d81d6 --- /dev/null +++ b/test/impl/random.cpp @@ -0,0 +1,25 @@ +#include +#include + +using uint64_t = unsigned long long; + +// https://en.wikipedia.org/wiki/Xorshift +uint64_t xorshift128plus(uint64_t state[2]) { + uint64_t t = state[0]; + uint64_t const s = state[1]; + state[0] = s; + t ^= t << 23; // a + t ^= t >> 17; // b + t ^= s ^ (s >> 26); // c + state[1] = t; + return t + s; +} + +TEST_CASE("Random case", "[obfs::Xorshift+]") { + constexpr size_t val = MAKE_RAND_VAL(100); + uint64_t state[2] = { val, val << 1 }; + + REQUIRE(obfs::Xorshiftplus::value == xorshift128plus(state)); + REQUIRE(obfs::Xorshiftplus::value == xorshift128plus(state)); + REQUIRE(obfs::Xorshiftplus::value == xorshift128plus(state)); +}