From a0b6c645169406ecaf8f57df10048131f18838b7 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 25 Nov 2015 13:34:01 +0100
Subject: [PATCH] Clean up test

---
 dune/common/test/fmatrixtest.cc | 46 +++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/dune/common/test/fmatrixtest.cc b/dune/common/test/fmatrixtest.cc
index 31f8d3e8f..cb75a7098 100644
--- a/dune/common/test/fmatrixtest.cc
+++ b/dune/common/test/fmatrixtest.cc
@@ -502,27 +502,32 @@ void test_invert ()
   A.invert();
 }
 
-// Make sure that a matrix with only NaN entries has norm NaN.
-// Prior to r6819, the infinity_norm would be zero; see also FS #1147.
+template <class M>
+void checkNormNAN(M const &v, int line) {
+  if (!std::isnan(v.frobenius_norm())) {
+    std::cerr << "error: norm not NaN: frobenius_norm() on line "
+              << line << " (type: " << Dune::className(v[0]) << ")"
+              << std::endl;
+    std::exit(-1);
+  }
+  if (!std::isnan(v.infinity_norm())) {
+    std::cerr << "error: norm not NaN: infinity_norm() on line "
+              << line << " (type: " << Dune::className(v[0]) << ")"
+              << std::endl;
+    std::exit(-1);
+  }
+}
+
+// Make sure that matrices with NaN entries have norm NaN.
+// See also bug flyspray/FS#1147
+template <typename T>
 void
-test_nan()
+test_nan(T const &mynan)
 {
-  double mynan = 0.0/0.0;
-
-  Dune::FieldMatrix<double, 2, 2> m2(mynan);
-  assert(std::isnan(m2.infinity_norm()));
-  assert(std::isnan(m2.frobenius_norm()));
-  assert(std::isnan(m2.frobenius_norm2()));
-
-  Dune::FieldMatrix<double, 0, 2> m02(mynan);
-  assert(0.0 == m02.infinity_norm());
-  assert(0.0 == m02.frobenius_norm());
-  assert(0.0 == m02.frobenius_norm2());
-
-  Dune::FieldMatrix<double, 2, 0> m20(mynan);
-  assert(0.0 == m20.infinity_norm());
-  assert(0.0 == m20.frobenius_norm());
-  assert(0.0 == m20.frobenius_norm2());
+  Dune::FieldMatrix<T, 2, 2> m = {
+    { mynan, mynan },
+    { mynan, mynan }
+  checkNormNAN(m, __LINE__);
 }
 
 // The computation of infinity_norm_real() was flawed from r6819 on
@@ -568,7 +573,8 @@ void test_initialisation()
 int main()
 {
   try {
-    test_nan();
+    double nan = std::nan("");
+    test_nan(nan);
     test_infinity_norms();
     test_initialisation();
 
-- 
GitLab