1 /* boost test_seed_seq.cpp
3 * Copyright Steven Watanabe 2010
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * $Id: test_seed_seq.cpp 79771 2012-07-27 18:15:55Z jewillco $
11 #include <boost/random/seed_seq.hpp>
12 #include <boost/assign/list_of.hpp>
13 #include <boost/config.hpp>
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
19 using boost::assign::list_of;
21 BOOST_AUTO_TEST_CASE(test_seed_seq) {
22 boost::uint32_t expected_param[4] = { 2, 3, 4, 0xdeadbeaf };
23 boost::uint32_t param[4] = { 2, 3, 4, 0xdeadbeaf };
24 boost::uint32_t store32[10];
25 boost::uint64_t store64[10];
26 boost::uint32_t expected[10] = {
38 std::fill_n(&store32[0], 10, 0);
39 std::fill_n(&store64[0], 10, 0);
40 boost::random::seed_seq seq;
41 seq.generate(&store32[0], &store32[0] + 10);
42 BOOST_CHECK_EQUAL_COLLECTIONS(
43 &store32[0], &store32[0] + 10, &expected[0], &expected[0] + 10);
44 seq.generate(&store64[0], &store64[0] + 10);
45 BOOST_CHECK_EQUAL_COLLECTIONS(
46 &store64[0], &store64[0] + 10, &expected[0], &expected[0] + 10);
47 BOOST_CHECK_EQUAL(seq.size(), 0u);
49 BOOST_CHECK_EQUAL_COLLECTIONS(
50 ¶m[0], ¶m[0] + 4, &expected_param[0], &expected_param[0] + 4);
52 boost::uint32_t expected_r[10] = {
65 std::vector<int> data = list_of(2)(3)(4);
67 std::fill_n(&store32[0], 10, 0);
68 std::fill_n(&store64[0], 10, 0);
69 std::fill_n(¶m[0], 3, 0);
70 boost::random::seed_seq seq_r(data);
71 seq_r.generate(&store32[0], &store32[0] + 10);
72 BOOST_CHECK_EQUAL_COLLECTIONS(
73 &store32[0], &store32[0] + 10, &expected_r[0], &expected_r[0] + 10);
74 seq_r.generate(&store64[0], &store64[0] + 10);
75 BOOST_CHECK_EQUAL_COLLECTIONS(
76 &store64[0], &store64[0] + 10, &expected_r[0], &expected_r[0] + 10);
77 BOOST_CHECK_EQUAL(seq_r.size(), 3u);
78 seq_r.param(¶m[0]);
79 BOOST_CHECK_EQUAL_COLLECTIONS(
80 ¶m[0], ¶m[0] + 4, &expected_param[0], &expected_param[0] + 4);
82 std::fill_n(&store32[0], 10, 0);
83 std::fill_n(&store64[0], 10, 0);
84 std::fill_n(¶m[0], 3, 0);
85 boost::random::seed_seq seq_it(data.begin(), data.end());
86 seq_it.generate(&store32[0], &store32[0] + 10);
87 BOOST_CHECK_EQUAL_COLLECTIONS(
88 &store32[0], &store32[0] + 10, &expected_r[0], &expected_r[0] + 10);
89 seq_it.generate(&store64[0], &store64[0] + 10);
90 BOOST_CHECK_EQUAL_COLLECTIONS(
91 &store64[0], &store64[0] + 10, &expected_r[0], &expected_r[0] + 10);
92 BOOST_CHECK_EQUAL(seq_it.size(), 3u);
93 seq_it.param(¶m[0]);
94 BOOST_CHECK_EQUAL_COLLECTIONS(
95 ¶m[0], ¶m[0] + 4, &expected_param[0], &expected_param[0] + 4);
97 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
98 std::fill_n(&store32[0], 10, 0);
99 std::fill_n(&store64[0], 10, 0);
100 std::fill_n(¶m[0], 3, 0);
101 boost::random::seed_seq seq_il = {2, 3, 4};
102 seq_il.generate(&store32[0], &store32[0] + 10);
103 BOOST_CHECK_EQUAL_COLLECTIONS(
104 &store32[0], &store32[0] + 10, &expected_r[0], &expected_r[0] + 10);
105 seq_il.generate(&store64[0], &store64[0] + 10);
106 BOOST_CHECK_EQUAL_COLLECTIONS(
107 &store64[0], &store64[0] + 10, &expected_r[0], &expected_r[0] + 10);
108 BOOST_CHECK_EQUAL(seq_il.size(), 3u);
109 seq_il.param(¶m[0]);
110 BOOST_CHECK_EQUAL_COLLECTIONS(
111 ¶m[0], ¶m[0] + 4, &expected_param[0], &expected_param[0] + 4);