From 74a5cc4fd675a2d1dbbbd4cba30e33ae1642c0b7 Mon Sep 17 00:00:00 2001
From: Oliver Sander <oliver.sander@tu-dresden.de>
Date: Thu, 18 Feb 2016 23:30:25 +0100
Subject: [PATCH] Test FieldVector for compliance with the dune-istl vector
 interface

The FieldVector class resides in dune-common, and is tested there.  However, we also
want to check it against the tests specifying the dune-istl vector interface in vectortest.hh,
therefore we add a second test for FieldVector to the dune-istl module.
---
 dune/istl/test/CMakeLists.txt     |  2 ++
 dune/istl/test/fieldvectortest.cc | 58 +++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
 create mode 100644 dune/istl/test/fieldvectortest.cc

diff --git a/dune/istl/test/CMakeLists.txt b/dune/istl/test/CMakeLists.txt
index f5fc866aa..0a998ea23 100644
--- a/dune/istl/test/CMakeLists.txt
+++ b/dune/istl/test/CMakeLists.txt
@@ -12,6 +12,8 @@ dune_add_test(SOURCES dotproducttest.cc)
 
 dune_add_test(SOURCES complexmatrixtest.cc)
 
+dune_add_test(SOURCES fieldvectortest.cc)
+
 dune_add_test(SOURCES matrixnormtest.cc)
 
 dune_add_test(SOURCES matrixutilstest.cc)
diff --git a/dune/istl/test/fieldvectortest.cc b/dune/istl/test/fieldvectortest.cc
new file mode 100644
index 000000000..14a37ad1c
--- /dev/null
+++ b/dune/istl/test/fieldvectortest.cc
@@ -0,0 +1,58 @@
+// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vi: set et ts=4 sw=2 sts=2:
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/** \file
+ * \brief Test the FieldVector class from dune-common with the unit tests for the dune-istl vector interface
+ *
+ * This test is exceptional: it is testing a class from dune-common!  This is because FieldVector is supposed
+ * to implement the dune-istl vector interface, but it resides in dune-common because most other modules
+ * also want to use it.  However, the tests for the dune-istl vector interface reside in dune-istl, and therefore
+ * the compliance test for FieldVector needs to be done in dune-istl, too.
+ */
+#include <complex>
+
+#include <dune/common/fvector.hh>
+
+#include <dune/istl/test/vectortest.hh>
+
+using namespace Dune;
+
+int main() try
+{
+  // Test a double vector
+  FieldVector<double,3> vDouble = {1.0, 2.0, 3.0};
+  testHomogeneousRandomAccessContainer(vDouble);
+  testConstructibility<decltype(vDouble)>();
+  testNorms(vDouble);
+  testVectorSpaceOperations(vDouble);
+
+  // Test a double vector of length 1
+  FieldVector<double,1> vDouble1 = {1.0};
+  testHomogeneousRandomAccessContainer(vDouble1);
+  testConstructibility<decltype(vDouble1)>();
+  testNorms(vDouble1);
+  testVectorSpaceOperations(vDouble1);
+
+  // Test a complex vector
+  FieldVector<std::complex<double>,3> vComplex = {{1.0, 1.0}, {2.0,2.0}, {3.0,3.0}};
+  testHomogeneousRandomAccessContainer(vComplex);
+  testConstructibility<decltype(vComplex)>();
+  testNorms(vComplex);
+  testVectorSpaceOperations(vComplex);
+
+  // Test a complex vector of length 1
+  FieldVector<std::complex<double>,1> vComplex1 = {{1.0,3.14}};
+  testHomogeneousRandomAccessContainer(vComplex1);
+  testConstructibility<decltype(vComplex1)>();
+  testNorms(vComplex1);
+  testVectorSpaceOperations(vComplex1);
+
+  return 0;
+}
+catch (std::exception& e) {
+  std::cerr << e.what() << std::endl;
+  return 1;
+}
-- 
GitLab