Changeset View
Changeset View
Standalone View
Standalone View
src/test/random_tests.cpp
Show All 22 Lines | BOOST_AUTO_TEST_CASE(fastrandom_tests) { | ||||
FastRandomContext ctx1(true); | FastRandomContext ctx1(true); | ||||
FastRandomContext ctx2(true); | FastRandomContext ctx2(true); | ||||
for (int i = 10; i > 0; --i) { | for (int i = 10; i > 0; --i) { | ||||
BOOST_CHECK_EQUAL(GetRand(std::numeric_limits<uint64_t>::max()), | BOOST_CHECK_EQUAL(GetRand(std::numeric_limits<uint64_t>::max()), | ||||
uint64_t{10393729187455219830U}); | uint64_t{10393729187455219830U}); | ||||
BOOST_CHECK_EQUAL(GetRandInt(std::numeric_limits<int>::max()), | BOOST_CHECK_EQUAL(GetRandInt(std::numeric_limits<int>::max()), | ||||
int{769702006}); | int{769702006}); | ||||
BOOST_CHECK_EQUAL(GetRandMicros(std::chrono::hours{1}).count(), | |||||
2917185654); | |||||
BOOST_CHECK_EQUAL(GetRandMillis(std::chrono::hours{1}).count(), | |||||
2144374); | |||||
} | } | ||||
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | ||||
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | ||||
BOOST_CHECK_EQUAL(ctx1.rand64(), ctx2.rand64()); | BOOST_CHECK_EQUAL(ctx1.rand64(), ctx2.rand64()); | ||||
BOOST_CHECK_EQUAL(ctx1.randbits(3), ctx2.randbits(3)); | BOOST_CHECK_EQUAL(ctx1.randbits(3), ctx2.randbits(3)); | ||||
BOOST_CHECK(ctx1.randbytes(17) == ctx2.randbytes(17)); | BOOST_CHECK(ctx1.randbytes(17) == ctx2.randbytes(17)); | ||||
BOOST_CHECK(ctx1.rand256() == ctx2.rand256()); | BOOST_CHECK(ctx1.rand256() == ctx2.rand256()); | ||||
BOOST_CHECK_EQUAL(ctx1.randbits(7), ctx2.randbits(7)); | BOOST_CHECK_EQUAL(ctx1.randbits(7), ctx2.randbits(7)); | ||||
BOOST_CHECK(ctx1.randbytes(128) == ctx2.randbytes(128)); | BOOST_CHECK(ctx1.randbytes(128) == ctx2.randbytes(128)); | ||||
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32()); | ||||
BOOST_CHECK_EQUAL(ctx1.randbits(3), ctx2.randbits(3)); | BOOST_CHECK_EQUAL(ctx1.randbits(3), ctx2.randbits(3)); | ||||
BOOST_CHECK(ctx1.rand256() == ctx2.rand256()); | BOOST_CHECK(ctx1.rand256() == ctx2.rand256()); | ||||
BOOST_CHECK(ctx1.randbytes(50) == ctx2.randbytes(50)); | BOOST_CHECK(ctx1.randbytes(50) == ctx2.randbytes(50)); | ||||
// Check that a nondeterministic ones are not | // Check that a nondeterministic ones are not | ||||
g_mock_deterministic_tests = false; | g_mock_deterministic_tests = false; | ||||
for (int i = 10; i > 0; --i) { | for (int i = 10; i > 0; --i) { | ||||
BOOST_CHECK(GetRand(std::numeric_limits<uint64_t>::max()) != | BOOST_CHECK(GetRand(std::numeric_limits<uint64_t>::max()) != | ||||
uint64_t{10393729187455219830U}); | uint64_t{10393729187455219830U}); | ||||
BOOST_CHECK(GetRandInt(std::numeric_limits<int>::max()) != | BOOST_CHECK(GetRandInt(std::numeric_limits<int>::max()) != | ||||
int{769702006}); | int{769702006}); | ||||
BOOST_CHECK(GetRandMicros(std::chrono::hours{1}) != | |||||
std::chrono::microseconds{2917185654}); | |||||
BOOST_CHECK(GetRandMillis(std::chrono::hours{1}) != | |||||
std::chrono::milliseconds{2144374}); | |||||
} | } | ||||
{ | { | ||||
FastRandomContext ctx3, ctx4; | FastRandomContext ctx3, ctx4; | ||||
// extremely unlikely to be equal | // extremely unlikely to be equal | ||||
BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); | BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); | ||||
} | } | ||||
{ | { | ||||
FastRandomContext ctx3, ctx4; | FastRandomContext ctx3, ctx4; | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |