From 7f6db806a1c92e59fbd484e7b23e6dd8609204eb Mon Sep 17 00:00:00 2001
From: Max Kahnt <max.kahnt@fu-berlin.de>
Date: Thu, 28 Sep 2017 18:45:58 +0200
Subject: [PATCH] Add test for resize from SumOperator.

---
 dune/solvers/test/sumoperatortest.cc | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/dune/solvers/test/sumoperatortest.cc b/dune/solvers/test/sumoperatortest.cc
index 39d05704..ca6c189c 100644
--- a/dune/solvers/test/sumoperatortest.cc
+++ b/dune/solvers/test/sumoperatortest.cc
@@ -170,6 +170,30 @@ bool check()
     return passed;
 }
 
+bool checkResize() try {
+  std::cout << "Checking resize from SumOperator ... ";
+  using namespace Dune;
+  using Block = FieldMatrix<double, 2, 6>;
+  using SparseMatrix = BCRSMatrix<Block>;
+  SparseMatrix sparseMatrix;
+  MatrixIndexSet indices(3,4);
+  indices.exportIdx(sparseMatrix);
+  using LowRankFactor = Matrix<Block>;
+  SumOperator<SparseMatrix, LowRankOperator<LowRankFactor>> sumOp;
+  sumOp.sparseMatrix() = sparseMatrix;
+  sumOp.lowRankMatrix().lowRankFactor() = LowRankFactor(5,6); // "weird" sizes should not matter
+  BlockVector<Dune::FieldVector<double, 2>> vector;
+  MatrixVector::resize(vector, sumOp);
+  if(vector.size() != 3)
+    DUNE_THROW(Exception, "Resize yields unexpected vector size.");
+  std::cout << "passed" << std::endl;
+  return true;
+} catch(Dune::Exception e) {
+  std::cout << " FAILED." << std::endl;
+  std::cout << "Exception was: " << e << std::endl;
+  return false;
+}
+
 int main(int argc, char** argv)
 {
     Dune::MPIHelper::instance(argc, argv);
@@ -194,5 +218,7 @@ int main(int argc, char** argv)
     passed = passed and check<Dune::BCRSMatrix<Block3>, Dune::Matrix<Block2> >();
     passed = passed and check<Dune::BCRSMatrix<Block3>, Dune::Matrix<Block3> >();
 
+    passed = passed and checkResize();
+
     return passed ? 0 : 1;
 }
-- 
GitLab