|
|
|
// Copyright (c) 2017 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "random.h"
|
|
|
|
|
|
|
|
#include "test/test_bitcoin.h"
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(random_tests, BasicTestingSetup)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(osrandom_tests)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(Random_SanityCheck());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(fastrandom_tests)
|
|
|
|
{
|
|
|
|
// Check that deterministic FastRandomContexts are deterministic
|
|
|
|
FastRandomContext ctx1(true);
|
|
|
|
FastRandomContext ctx2(true);
|
|
|
|
|
|
|
|
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.randbits(3), ctx2.randbits(3));
|
|
|
|
BOOST_CHECK_EQUAL(ctx1.randbits(7), ctx2.randbits(7));
|
|
|
|
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32());
|
|
|
|
BOOST_CHECK_EQUAL(ctx1.randbits(3), ctx2.randbits(3));
|
|
|
|
|
|
|
|
// Check that a nondeterministic ones are not
|
|
|
|
FastRandomContext ctx3;
|
|
|
|
FastRandomContext ctx4;
|
|
|
|
BOOST_CHECK(ctx3.rand64() != ctx4.rand64()); // extremely unlikely to be equal
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|