From: Reza Rastak Date: Mon, 6 Jan 2020 07:18:31 +0000 (-0800) Subject: tests updated to be independent of RNG details X-Git-Tag: v9.2.0-rc1~735^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a3f61d45a93d54610a7bbe1e461059dab965f50;p=dealii.git tests updated to be independent of RNG details --- diff --git a/tests/base/function_parser_09.cc b/tests/base/function_parser_09.cc index 46028ef688..1cadc4368c 100644 --- a/tests/base/function_parser_09.cc +++ b/tests/base/function_parser_09.cc @@ -41,15 +41,30 @@ eval(const std::string &exp) } +bool +satisfies_randomness(std::vector &v) +{ + // check that consecutive numbers are not the same + for (unsigned int i = 1; i < v.size(); ++i) + if (v[i - 1] == v[i]) + return false; + // Check that the numbers are between 0 and 1 + return std::all_of(v.begin(), v.end(), [](double n) { + return (n >= 0.) && (n <= 1.); + }); +} + + int main() { initlog(); - double random = eval("rand()"); // random seed + std::vector rands{eval("rand_seed(10)"), + eval("rand()"), + eval("rand_seed(10)"), + eval("rand_seed(10)")}; - if (0.0 <= random && random <= 1.0) + if (satisfies_randomness(rands)) deallog << "OK" << std::endl; - - deallog << eval("rand_seed(10)") << std::endl; } diff --git a/tests/base/function_parser_09.with_muparser=true.output b/tests/base/function_parser_09.with_muparser=true.output index 03a86172f4..0fd8fc12f0 100644 --- a/tests/base/function_parser_09.with_muparser=true.output +++ b/tests/base/function_parser_09.with_muparser=true.output @@ -1,3 +1,2 @@ DEAL::OK -DEAL::0.298761 diff --git a/tests/base/function_parser_10.cc b/tests/base/function_parser_10.cc index bbc51fe5ec..452417855d 100644 --- a/tests/base/function_parser_10.cc +++ b/tests/base/function_parser_10.cc @@ -37,15 +37,30 @@ eval(const std::string &exp) } +bool +satisfies_randomness(std::vector &v) +{ + // check that consecutive numbers are not the same + for (unsigned int i = 1; i < v.size(); ++i) + if (v[i - 1] == v[i]) + return false; + // Check that the numbers are between 0 and 1 + return std::all_of(v.begin(), v.end(), [](double n) { + return (n >= 0.) && (n <= 1.); + }); +} + + int main() { initlog(); - double random = eval("rand()"); // random seed + std::vector rands{eval("rand_seed(10)"), + eval("rand()"), + eval("rand_seed(10)"), + eval("rand_seed(10)")}; - if (0.0 <= random && random <= 1.0) + if (satisfies_randomness(rands)) deallog << "OK" << std::endl; - - deallog << eval("rand_seed(10)") << std::endl; } diff --git a/tests/base/function_parser_10.with_muparser=true.output b/tests/base/function_parser_10.with_muparser=true.output index 03a86172f4..0fd8fc12f0 100644 --- a/tests/base/function_parser_10.with_muparser=true.output +++ b/tests/base/function_parser_10.with_muparser=true.output @@ -1,3 +1,2 @@ DEAL::OK -DEAL::0.298761