Changeset View
Changeset View
Standalone View
Standalone View
src/test/random_tests.cpp
Show All 30 Lines | BOOST_AUTO_TEST_CASE(fastrandom_tests) { | ||||
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 | ||||
FastRandomContext ctx3; | { | ||||
FastRandomContext 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; | |||||
BOOST_CHECK(ctx3.rand256() != ctx4.rand256()); | BOOST_CHECK(ctx3.rand256() != ctx4.rand256()); | ||||
} | |||||
{ | |||||
FastRandomContext ctx3, ctx4; | |||||
BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7)); | BOOST_CHECK(ctx3.randbytes(7) != ctx4.randbytes(7)); | ||||
} | } | ||||
} | |||||
BOOST_AUTO_TEST_CASE(fastrandom_randbits) { | BOOST_AUTO_TEST_CASE(fastrandom_randbits) { | ||||
FastRandomContext ctx1; | FastRandomContext ctx1; | ||||
FastRandomContext ctx2; | FastRandomContext ctx2; | ||||
for (int bits = 0; bits < 63; ++bits) { | for (int bits = 0; bits < 63; ++bits) { | ||||
for (int j = 0; j < 1000; ++j) { | for (int j = 0; j < 1000; ++j) { | ||||
uint64_t rangebits = ctx1.randbits(bits); | uint64_t rangebits = ctx1.randbits(bits); | ||||
BOOST_CHECK_EQUAL(rangebits >> bits, uint64_t(0)); | BOOST_CHECK_EQUAL(rangebits >> bits, uint64_t(0)); | ||||
Show All 25 Lines |