From f2e47d0a3a63655d87c20c230927db046a86e9e9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 19 Apr 2015 16:57:51 -0500 Subject: [PATCH] Add test. --- .../base/generate_normal_random_number_01.cc | 87 +++++++++++++++++++ .../generate_normal_random_number_01.output | 2 + 2 files changed, 89 insertions(+) create mode 100644 tests/base/generate_normal_random_number_01.cc create mode 100644 tests/base/generate_normal_random_number_01.output diff --git a/tests/base/generate_normal_random_number_01.cc b/tests/base/generate_normal_random_number_01.cc new file mode 100644 index 0000000000..f12745227f --- /dev/null +++ b/tests/base/generate_normal_random_number_01.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2005 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test Utilities::generate_random_normal_number. this function is +// supposed to be thread-safe, so check that a standard measure of +// normality holds for the numbers produced on different threads + +#include "../tests.h" +#include +#include +#include +#include + +#include + + +std::pair test () +{ + const double mu = 13; + const double sigma = 3; + + unsigned int N = 1000000; + double sum = 0; + double sum_square = 0; + for (unsigned int i=0; i > tg[4]; + tg[0] = Threads::new_thread (&test); + tg[1] = Threads::new_thread (&test); + tg[2] = Threads::new_thread (&test); + tg[3] = Threads::new_thread (&test); + + tg[0].join(); + tg[1].join(); + tg[2].join(); + tg[3].join(); + + + // the random number generator is thread-local, so we should get the + // same result every time + deallog << tg[0].return_value().first + << ' ' + << tg[0].return_value().second + << std::endl; + AssertThrow (tg[1].return_value() == tg[0].return_value(), + ExcInternalError()); + AssertThrow (tg[2].return_value() == tg[0].return_value(), + ExcInternalError()); + AssertThrow (tg[3].return_value() == tg[0].return_value(), + ExcInternalError()); +} diff --git a/tests/base/generate_normal_random_number_01.output b/tests/base/generate_normal_random_number_01.output new file mode 100644 index 0000000000..d9c90029f7 --- /dev/null +++ b/tests/base/generate_normal_random_number_01.output @@ -0,0 +1,2 @@ + +DEAL::12.9995 3.00072 -- 2.39.5