]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests for iterators over DynamicSparsityPattern objects.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 13 Apr 2015 13:51:10 +0000 (08:51 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 13 Apr 2015 13:51:10 +0000 (08:51 -0500)
tests/bits/dynamic_sparsity_pattern_iterator_01.cc [new file with mode: 0644]
tests/bits/dynamic_sparsity_pattern_iterator_01.output [new file with mode: 0644]
tests/bits/dynamic_sparsity_pattern_iterator_02.cc [new file with mode: 0644]
tests/bits/dynamic_sparsity_pattern_iterator_02.output [new file with mode: 0644]

diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_01.cc b/tests/bits/dynamic_sparsity_pattern_iterator_01.cc
new file mode 100644 (file)
index 0000000..becd8af
--- /dev/null
@@ -0,0 +1,79 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2004 - 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 DynamicSparsityPattern::iterator
+
+#include "../tests.h"
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  DynamicSparsityPattern sp (5,5);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if ((i+2*j+1) % 3 == 0)
+        sp.add (i,j);
+  sp.compress ();
+
+  DynamicSparsityPattern::const_iterator i = sp.begin();
+  for (; i!=sp.end(); ++i)
+    deallog << i->row() << ' ' << i->column() << std::endl;
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Exception on processing: " << std::endl
+              << exc.what() << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Unknown exception!" << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_01.output b/tests/bits/dynamic_sparsity_pattern_iterator_01.output
new file mode 100644 (file)
index 0000000..3f3197a
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEAL::0 1
+DEAL::0 4
+DEAL::1 2
+DEAL::2 0
+DEAL::2 3
+DEAL::3 1
+DEAL::3 4
+DEAL::4 2
+DEAL::OK
diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_02.cc b/tests/bits/dynamic_sparsity_pattern_iterator_02.cc
new file mode 100644 (file)
index 0000000..1c58e99
--- /dev/null
@@ -0,0 +1,82 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2004 - 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 DynamicSparsityPattern::iterator with sparsity patterns that
+// have empty rows
+
+#include "../tests.h"
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  DynamicSparsityPattern sp (5,5);
+  sp.add (0,0);
+  sp.add (3,3);
+  sp.compress ();
+
+  DynamicSparsityPattern::const_iterator i = sp.begin();
+  for (; i!=sp.end(); ++i)
+    deallog << i->row() << ' ' << i->column() << std::endl;
+
+  deallog << "OK" << std::endl;
+
+  i = sp.begin(1);
+  deallog << i->row() << ' ' << i->column() << std::endl;
+  deallog << "OK" << std::endl;  
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Exception on processing: " << std::endl
+              << exc.what() << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Unknown exception!" << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_02.output b/tests/bits/dynamic_sparsity_pattern_iterator_02.output
new file mode 100644 (file)
index 0000000..517e23f
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::0 0
+DEAL::3 3
+DEAL::OK
+DEAL::3 3
+DEAL::OK

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.