diff options
author | MarcoFalke <falke.marco@gmail.com> | 2018-03-22 12:21:41 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2018-03-22 12:21:46 -0400 |
commit | f686002a8eba820a40ac2f34a6e8f57b2b5cc54c (patch) | |
tree | af61b257c03dc5f00c5ae640a51f7b2e364027f5 /src/test | |
parent | c290508a5ebf7e26c68fc0bb01382f708e645402 (diff) | |
parent | 1ec1602a4549f6b68586cead8eff701bceb624f5 (diff) |
Merge #12742: Make FastRandomContext support standard C++11 RNG interface
1ec1602a45 Make FastRandomContext support standard C++11 RNG interface (Pieter Wuille)
Pull request description:
This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like `std::shuffle`.
Tree-SHA512: 935eae9c4fae31e1964c16d9cf9d0fcfa899e04567f010d8b3e1ff824e55e2392aa838ba743d03c1b2a5010c5b8da04343f453983dfeed83747d85828a564713
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/random_tests.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/random_tests.cpp b/src/test/random_tests.cpp index 1ca5a53d72..623ed239f0 100644 --- a/src/test/random_tests.cpp +++ b/src/test/random_tests.cpp @@ -8,6 +8,9 @@ #include <boost/test/unit_test.hpp> +#include <random> +#include <algorithm> + BOOST_FIXTURE_TEST_SUITE(random_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(osrandom_tests) @@ -57,4 +60,23 @@ BOOST_AUTO_TEST_CASE(fastrandom_randbits) } } +/** Does-it-compile test for compatibility with standard C++11 RNG interface. */ +BOOST_AUTO_TEST_CASE(stdrandom_test) +{ + FastRandomContext ctx; + std::uniform_int_distribution<int> distribution(3, 9); + for (int i = 0; i < 100; ++i) { + int x = distribution(ctx); + BOOST_CHECK(x >= 3); + BOOST_CHECK(x <= 9); + + std::vector<int> test{1,2,3,4,5,6,7,8,9,10}; + std::shuffle(test.begin(), test.end(), ctx); + for (int j = 1; j <= 10; ++j) { + BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end()); + } + } + +} + BOOST_AUTO_TEST_SUITE_END() |