31 namespace Test_RandomNumbers_SFMT {
32 const std::string
test_name =
"RandomNumbers.SFMT.Uniform";
36 const std::string filename_input =
"test_RandomNumbers_SFMT_Uniform.yaml";
42 #ifdef USE_TESTMANAGER_AUTOREGISTER
60 const int Nseed = params_test.
get_int(
"number_of_seeds");
61 const int iseed_base = params_test.
get_int(
"int_seed_base");
62 const int Nrand = params_test.
get_int(
"number_of_samples");
63 const string str_vlevel = params_test.
get_string(
"verbose_level");
65 const bool do_check = params_test.
is_set(
"expected_result");
66 const double expected_result = do_check ? params_test.
get_double(
"expected_result") : 0.0;
74 vout.
general(vl,
" vlevel = %s\n", str_vlevel.c_str());
87 vout.
general(vl,
" number of samples = %10d\n", Nrand);
92 for (
int iseed = 0; iseed < Nseed; ++iseed) {
93 int iseed2 = iseed_base + iseed;
95 unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed2));
98 for (
int i = 0; i < Nrand; ++i) {
99 double rand1 = rand->get();
100 double rand2 = rand->get();
101 double r = rand1 * rand1 + rand2 * rand2;
103 if (r < 1.0) { ++Npi; }
107 double pi_exp = (4.0 * Npi) / Nrand;
110 t2 += pi_exp * pi_exp;
113 vout.
general(vl,
" %10d %14.10f\n", iseed2, pi_exp);
116 const double api = t1 / (double)Nseed;
117 const double vpi = t2 / (double)Nseed - api * api;
118 const double dpi = sqrt(vpi);
119 const double epi = dpi / sqrt((
double)Nseed - 1);
121 const double pi = 3.141592653589793;
128 const double result = api;
137 vout.
detailed(vl,
"check skipped: expected_result not set.\n\n");
142 #endif // USE_SFMTLIB
void detailed(const char *format,...)
void general(const char *format,...)
const std::string test_name
int get_int(const string &key) const
int uniform_calc_pi(void)
Parameters lookup(const string &key) const
static bool RegisterTest(const std::string &key, const Test_function func)
double get_double(const string &key) const
bool is_set(const string &key) const
static void read(const std::string ¶ms_file, Parameters ¶ms)
int verify(const double result, const double expected, double eps)
string get_string(const string &key) const
static VerboseLevel set_verbose_level(const std::string &str)