]> https://gitweb.dealii.org/ - dealii.git/commitdiff
tests updated to be independent of RNG details 9204/head
authorReza Rastak <rastak@stanford.edu>
Mon, 6 Jan 2020 07:18:31 +0000 (23:18 -0800)
committerReza Rastak <rastak@stanford.edu>
Mon, 6 Jan 2020 07:18:31 +0000 (23:18 -0800)
tests/base/function_parser_09.cc
tests/base/function_parser_09.with_muparser=true.output
tests/base/function_parser_10.cc
tests/base/function_parser_10.with_muparser=true.output

index 46028ef688751910cced3f48a36b411da157a177..1cadc4368c9c95dfcb24c215283b25fd5100d528 100644 (file)
@@ -41,15 +41,30 @@ eval(const std::string &exp)
 }
 
 
+bool
+satisfies_randomness(std::vector<double> &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<double> 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;
 }
index 03a86172f4202fb25a3fcb382bf5484272b96c51..0fd8fc12f0b442283edd8868867114c242b04d11 100644 (file)
@@ -1,3 +1,2 @@
 
 DEAL::OK
-DEAL::0.298761
index bbc51fe5ec8fbd12cd4874ac7f0cf57fdd87f2e5..452417855df172be0cfe7c33c7d2fd7a598fd3dd 100644 (file)
@@ -37,15 +37,30 @@ eval(const std::string &exp)
 }
 
 
+bool
+satisfies_randomness(std::vector<double> &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<double> 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;
 }
index 03a86172f4202fb25a3fcb382bf5484272b96c51..0fd8fc12f0b442283edd8868867114c242b04d11 100644 (file)
@@ -1,3 +1,2 @@
 
 DEAL::OK
-DEAL::0.298761

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.