15 #define GETTEXT_DOMAIN "wesnoth-test" 17 #include <boost/test/unit_test.hpp> 24 BOOST_AUTO_TEST_SUITE( rng )
32 for (
int i = 0;
i < 9999 ;
i++) {
35 unsigned long val = rng();
36 BOOST_CHECK_EQUAL( val , 4123659995U );
43 std::stringstream stream;
44 stream << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed;
46 std::string seed_str = stream.str();
61 uint32_t seed3 = 1123581321;
62 std::stringstream stream2;
63 stream2 << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed3;
64 std::string seed_str3 = stream2.str();
78 BOOST_CHECK (seed != seed3);
79 BOOST_CHECK (seed_str != seed_str3);
86 std::stringstream stream;
87 stream << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed;
88 std::string seed_str = stream.str();
91 cfg[
"random_seed"] = seed_str;
92 cfg[
"random_calls"] = 0;
106 uint32_t seed3 = 1123581321;
107 std::stringstream stream2;
108 stream2 << std::setfill(
'0') << std::setw(
sizeof(uint32_t)*2) << std::hex << seed3;
109 std::string seed_str3 = stream2.str();
112 cfg2[
"random_seed"] = seed_str3;
113 cfg2[
"random_calls"] = 0;
128 BOOST_CHECK (seed != seed3);
129 BOOST_CHECK (seed_str != seed_str3);
135 cfg[
"random_seed"] =
"5eedf00d";
136 cfg[
"random_calls"] = 0;
141 BOOST_CHECK(rng1 == rng2);
142 for (
int i = 0;
i < 10 ;
i++) {
150 cfg[
"random_seed"] =
"18da5eed";
151 cfg[
"random_calls"] = 9999;
156 BOOST_CHECK(rng1 == rng2);
157 for (
int i = 0;
i < 10 ;
i++) {
171 BOOST_CHECK(rng1 == rng2);
172 for (
int i = 0;
i < 10 ;
i++) {
181 for (
int i = 0;
i < 5;
i++) {
191 BOOST_CHECK(rng1 == rng2);
198 cfg[
"random_seed"] =
"5eedc0de";
199 cfg[
"random_calls"] = 0;
203 for (
int i = 0;
i < 9999 ;
i++) {
216 BOOST_CHECK (rng == rng2);
219 BOOST_CHECK (result1 == result2);
230 BOOST_CHECK (rng == rng3);
233 BOOST_CHECK (result3 == result4);
238 void validate_seed_string(std::string seed_str)
241 cfg[
"random_seed"] = seed_str;
242 cfg[
"random_calls"] = 0;
246 for (
int i = 0;
i < 9999 ;
i++) {
256 for (
int i = 0;
i < 9999 ;
i++) {
261 BOOST_CHECK(rng1 == rng2);
270 validate_seed_string(
"0000badd");
271 validate_seed_string(
"00001234");
272 validate_seed_string(
"deadbeef");
273 validate_seed_string(
"12345678");
274 validate_seed_string(
"00009999");
275 validate_seed_string(
"ffffaaaa");
276 validate_seed_string(
"11110000");
277 validate_seed_string(
"10101010");
278 validate_seed_string(
"aaaa0000");
283 std::string validate_get_random_int_seed_generator()
290 #define validation_get_random_int_num_draws 19999 292 #define validation_get_random_int_max 32000 294 #define validation_get_random_int_correct_answer 10885 307 cfg[
"random_seed"] = validate_get_random_int_seed_generator();
312 auto gen_ = std::make_shared<randomness::rng_deterministic>(mt_);
320 auto gen_ = std::make_shared<randomness::synced_rng>(validate_get_random_int_seed_generator);
331 BOOST_AUTO_TEST_SUITE_END()
#define validation_get_random_int_num_draws
uint32_t get_next_random()
Get a new random number.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string get_random_seed_str() const
BOOST_AUTO_TEST_CASE(validate_mt19937)
uint32_t get_random_seed() const
#define validation_get_random_int_correct_answer
unsigned int get_random_calls() const
#define validation_get_random_int_max
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.
A config object defines a single node in a WML file, with access to child nodes.