16 #define GETTEXT_DOMAIN "wesnoth-test"
18 #include <boost/test/unit_test.hpp>
33 for (
int i = 0;
i < 9999 ;
i++) {
35 static_cast<void>(rng());
37 unsigned long val = rng();
38 BOOST_CHECK_EQUAL( val , 4123659995U );
45 std::stringstream stream;
46 stream << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed;
48 std::string seed_str = stream.str();
63 uint32_t seed3 = 1123581321;
64 std::stringstream stream2;
65 stream2 << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed3;
66 std::string seed_str3 = stream2.str();
80 BOOST_CHECK (seed != seed3);
81 BOOST_CHECK (seed_str != seed_str3);
88 std::stringstream stream;
89 stream << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed;
90 std::string seed_str = stream.str();
93 cfg[
"random_seed"] = seed_str;
94 cfg[
"random_calls"] = 0;
108 uint32_t seed3 = 1123581321;
109 std::stringstream stream2;
110 stream2 << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed3;
111 std::string seed_str3 = stream2.str();
114 cfg2[
"random_seed"] = seed_str3;
115 cfg2[
"random_calls"] = 0;
130 BOOST_CHECK (seed != seed3);
131 BOOST_CHECK (seed_str != seed_str3);
137 cfg[
"random_seed"] =
"5eedf00d";
138 cfg[
"random_calls"] = 0;
143 BOOST_CHECK(rng1 == rng2);
144 for (
int i = 0;
i < 10 ;
i++) {
152 cfg[
"random_seed"] =
"18da5eed";
153 cfg[
"random_calls"] = 9999;
158 BOOST_CHECK(rng1 == rng2);
159 for (
int i = 0;
i < 10 ;
i++) {
173 BOOST_CHECK(rng1 == rng2);
174 for (
int i = 0;
i < 10 ;
i++) {
183 for (
int i = 0;
i < 5;
i++) {
193 BOOST_CHECK(rng1 == rng2);
200 cfg[
"random_seed"] =
"5eedc0de";
201 cfg[
"random_calls"] = 0;
205 for (
int i = 0;
i < 9999 ;
i++) {
218 BOOST_CHECK (rng == rng2);
221 BOOST_CHECK (result1 == result2);
232 BOOST_CHECK (rng == rng3);
235 BOOST_CHECK (result3 == result4);
240 void validate_seed_string(std::string seed_str)
243 cfg[
"random_seed"] = seed_str;
244 cfg[
"random_calls"] = 0;
248 for (
int i = 0;
i < 9999 ;
i++) {
249 rng1.get_next_random();
253 cfg2[
"random_seed"] = rng1.get_random_seed_str();
254 cfg2[
"random_calls"] = rng1.get_random_calls();
258 for (
int i = 0;
i < 9999 ;
i++) {
259 rng1.get_next_random();
260 rng2.get_next_random();
263 BOOST_CHECK(rng1 == rng2);
264 BOOST_CHECK(rng1.get_next_random() == rng2.get_next_random());
272 validate_seed_string(
"0000badd");
273 validate_seed_string(
"00001234");
274 validate_seed_string(
"deadbeef");
275 validate_seed_string(
"12345678");
276 validate_seed_string(
"00009999");
277 validate_seed_string(
"ffffaaaa");
278 validate_seed_string(
"11110000");
279 validate_seed_string(
"10101010");
280 validate_seed_string(
"aaaa0000");
285 std::string validate_get_random_int_seed_generator()
292 #define validation_get_random_int_num_draws 19999
294 #define validation_get_random_int_max 32000
296 #define validation_get_random_int_correct_answer 10885
309 cfg[
"random_seed"] = validate_get_random_int_seed_generator();
314 auto gen_ = std::make_shared<randomness::rng_deterministic>(mt_);
322 auto gen_ = std::make_shared<randomness::synced_rng>(validate_get_random_int_seed_generator);
333 BOOST_AUTO_TEST_SUITE_END()
A config object defines a single node in a WML file, with access to child nodes.
std::string get_random_seed_str() const
uint32_t get_random_seed() const
uint32_t get_next_random()
Get a new random number.
void seed_random(const std::string &seed, const unsigned int call_count=0)
Same as uint32_t version, but uses a stringstream to convert given hex string.
unsigned int get_random_calls() const
Definitions for the interface to Wesnoth Markup Language (WML).
BOOST_AUTO_TEST_SUITE(filesystem)
BOOST_AUTO_TEST_CASE(validate_mt19937)
#define validation_get_random_int_max
#define validation_get_random_int_num_draws
#define validation_get_random_int_correct_answer