From 4a3f61d45a93d54610a7bbe1e461059dab965f50 Mon Sep 17 00:00:00 2001 From: Reza Rastak Date: Sun, 5 Jan 2020 23:18:31 -0800 Subject: [PATCH] tests updated to be independent of RNG details --- tests/base/function_parser_09.cc | 23 +++++++++++++++---- ...nction_parser_09.with_muparser=true.output | 1 - tests/base/function_parser_10.cc | 23 +++++++++++++++---- ...nction_parser_10.with_muparser=true.output | 1 - 4 files changed, 38 insertions(+), 10 deletions(-) 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 -- 2.39.5