11#include <boost/test/unit_test.hpp>
50 BOOST_CHECK_EQUAL(7, ctx.rand_uniform_delay(time_point, 9
s).time_since_epoch().count());
51 BOOST_CHECK_EQUAL(-6, ctx.rand_uniform_delay(time_point, -9
s).time_since_epoch().count());
52 BOOST_CHECK_EQUAL(1, ctx.rand_uniform_delay(time_point, 0
s).time_since_epoch().count());
53 BOOST_CHECK_EQUAL(4652286523065884857, ctx.rand_uniform_delay(time_point, 9223372036854775807
s).time_since_epoch().count());
54 BOOST_CHECK_EQUAL(-8813961240025683129, ctx.rand_uniform_delay(time_point, -9223372036854775807
s).time_since_epoch().count());
55 BOOST_CHECK_EQUAL(26443, ctx.rand_uniform_delay(time_point, 9h).time_since_epoch().count());
61 BOOST_CHECK(ctx1.randbytes(17) == ctx2.randbytes(17));
64 BOOST_CHECK(ctx1.randbytes(128) == ctx2.randbytes(128));
68 BOOST_CHECK(ctx1.randbytes(50) == ctx2.randbytes(50));
71 using duration = std::chrono::microseconds;
119 for (
int bits = 0; bits < 63; ++bits) {
120 for (
int j = 0; j < 1000; ++j) {
121 uint64_t rangebits = ctx1.
randbits(bits);
123 uint64_t range = (uint64_t{1}) << bits | rangebits;
135 int ctx_test_bitsleft{0};
138 for (
int i = 0; i < 5; ++i) {
142 std::vector<std::pair<uint64_t, uint64_t>> seen(2080 * 64);
145 for (
int j = 0; j < 1000; ++j) {
147 int bits = ctx_lens.
rand64() % 65;
149 uint64_t gen = ctx_test1.randbits(bits);
154 }
else if (bits == 1) {
156 }
else if (bits == 7) {
158 }
else if (bits == 32) {
160 }
else if (bits == 51) {
162 }
else if (bits == 64) {
171 for (
int bit = 0; bit < bits; ++bit) {
172 int idx = bit + (bits * (bits - 1)) / 2 + 2080 * ctx_test_bitsleft;
173 seen[idx].first += 1;
174 seen[idx].second += (gen >> bit) & 1;
177 if (bits > ctx_test_bitsleft) {
178 ctx_test_bitsleft = ctx_test_bitsleft + 64 - bits;
180 ctx_test_bitsleft -= bits;
184 if (std::all_of(seen.begin(), seen.end(), [](
const auto& x) {
return x.first >= 242; }))
break;
188 for (
const auto& val : seen) {
189 assert(fabs(val.first * 0.5 - val.second) < sqrt(val.first * 0.25) * 7.78);
198 std::uniform_int_distribution<int> distribution(3, 9);
199 for (
int i = 0; i < 100; ++i) {
200 int x = distribution(ctx);
204 std::vector<int> test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
205 std::shuffle(test.begin(), test.end(), ctx);
206 for (
int j = 1; j <= 10; ++j) {
207 BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
216 uint32_t counts[5 * 5 * 5 * 5 * 5] = {0};
217 for (
int i = 0; i < 12000; ++i) {
218 int data[5] = {0, 1, 2, 3, 4};
219 std::shuffle(std::begin(
data), std::end(
data), ctx);
223 unsigned int sum = 0;
224 double chi_score = 0.0;
225 for (
int i = 0; i < 5 * 5 * 5 * 5 * 5; ++i) {
226 int i1 = i % 5, i2 = (i / 5) % 5, i3 = (i / 25) % 5, i4 = (i / 125) % 5, i5 = i / 625;
227 uint32_t
count = counts[i];
228 if (i1 == i2 || i1 == i3 || i1 == i4 || i1 == i5 || i2 == i3 || i2 == i4 || i2 == i5 || i3 == i4 || i3 == i5 || i4 == i5) {
231 chi_score += ((
count - 100.0) * (
count - 100.0)) / 100.0;
246 BOOST_TEST(0x6f68e1e7e2646ee1 == rng());
247 BOOST_TEST(0xbf971b7f454094ad == rng());
248 BOOST_TEST(0x48f2de556f30de38 == rng());
249 BOOST_TEST(0x6ea7c59f89bbfc75 == rng());
252 rng.
Reseed(0x1a26f3fa8546b47a);
253 BOOST_TEST(0xc8dc5e08d844ac7d == rng());
254 BOOST_TEST(0x5b5f1f6d499dad1b == rng());
255 BOOST_TEST(0xbeb0031f93313d6f == rng());
256 BOOST_TEST(0xbfbcf4f43a264497 == rng());
uint64_t rand64() noexcept
Generate a random 64-bit integer.
constexpr void Reseed(uint64_t seedval) noexcept
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
uint256 rand256() noexcept
generate a random uint256.
std::vector< B > randbytes(size_t len) noexcept
Generate random bytes.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool Random_SanityCheck()
Check that OS randomness is available and returning the requested number of bytes.
BOOST_AUTO_TEST_CASE(osrandom_tests)
@ ZEROS
Seed with a compile time constant of zeros.
std::chrono::time_point< std::chrono::steady_clock, std::chrono::seconds > SteadySeconds