]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Improve move constructor tests 5646/head
authorBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 19 Dec 2017 01:58:16 +0000 (20:58 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 19 Dec 2017 01:58:16 +0000 (20:58 -0500)
Improve the move constructor tests of TrilinosWrappers::SparseMatrix and
TrilinosWrappers::SparsityPattern by checking the object whose data has been
stolen can be reinitialized

tests/trilinos/sparse_matrix_08.cc
tests/trilinos/sparsity_pattern_04.cc

index ab1ee3b1fe07bcc0481e36f519466089054ca215..927d4c18e661e4f173549916a8147912cd841e52 100644 (file)
@@ -14,7 +14,8 @@
 // ---------------------------------------------------------------------
 
 
-// Test move constructor
+// Test move constructor of sparse matrix and check that the matrix that has
+// been move can be reinitialized
 
 #include "../tests.h"
 #include <deal.II/base/utilities.h>
@@ -41,8 +42,8 @@ int main (int argc,char **argv)
   A.add (2, 1, 2.0);
   A.compress(VectorOperation::add);
 
+  // Check that the B stole the data of A
   TrilinosWrappers::SparseMatrix B(std::move(A));
-
   for (unsigned int i=0; i<3; ++i)
     for (unsigned int j=0; j<3; ++j)
       {
@@ -56,5 +57,25 @@ int main (int argc,char **argv)
           }
       }
 
+  // Check that A can be reinitialized
+  TrilinosWrappers::SparsityPattern sp_2 (partitioning);
+  sp_2.add (1,2);
+  sp_2.compress();
+  A.reinit(sp_2);
+  A.add(1, 2, 2.0);
+  A.compress(VectorOperation::add);
+  for (unsigned int i=0; i<3; ++i)
+    for (unsigned int j=0; j<3; ++j)
+      {
+        if ((i == 1) && (j == 2))
+          {
+            AssertThrow(A.el(i,j) == 2, ExcInternalError());
+          }
+        else
+          {
+            AssertThrow(A.el(i,j) == 0, ExcInternalError());
+          }
+      }
+
   deallog << "OK" << std::endl;
 }
index f45898ec1f515842aceaa6d04331a2318cf2096e..212fabf0303749e04195a75a48af5a662f37c7d7 100644 (file)
@@ -14,6 +14,9 @@
 // ---------------------------------------------------------------------
 
 
+// Test the move constructor of the sparsity pattern and check the sparsity
+// pattern whose data have been stolen can be reinitialized
+
 #include "../tests.h"
 #include <deal.II/lac/trilinos_sparsity_pattern.h>
 #include <deal.II/base/utilities.h>
@@ -33,17 +36,35 @@ int main (int argc, char **argv)
   A.add(2,1);
   A.compress();
 
+  // Check the move constructor
   TrilinosWrappers::SparsityPattern B(std::move(A));
   for (unsigned int i=0; i<3; ++i)
     for (unsigned int j=0; j<3; ++j)
       {
         if ((i == 2) && (j == 1))
           {
-            AssertThrow(B.exist(i,j) == true, ExcInternalError());
+            AssertThrow(B.exists(i,j) == true, ExcInternalError());
+          }
+        else
+          {
+            AssertThrow(B.exists(i,j) == false, ExcInternalError());
+          }
+      }
+
+  // Check that A can be reinitialized
+  A.reinit(partitioning);
+  A.add(1,2);
+  A.compress();
+  for (unsigned int i=0; i<3; ++i)
+    for (unsigned int j=0; j<3; ++j)
+      {
+        if ((i == 1) && (j == 2))
+          {
+            AssertThrow(A.exists(i,j) == true, ExcInternalError());
           }
         else
           {
-            AssertThrow(B.exist(i,j) == false, ExcInternalError());
+            AssertThrow(A.exists(i,j) == false, ExcInternalError());
           }
       }
 

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.