]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
More tests.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 6 Feb 2004 20:19:04 +0000 (20:19 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 6 Feb 2004 20:19:04 +0000 (20:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@8418 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/Makefile
tests/bits/sparse_matrix_01a.cc [new file with mode: 0644]

index f049c910b9bca98897010da0ba970b5e4444f47d..79e98f6ac9f42e26684f3bf9b5266bbed4e7db24 100644 (file)
@@ -138,6 +138,7 @@ find_cell_1.exe         : find_cell_1.g.$(OBJEXT)          $(libraries)
 find_cell_2.exe         : find_cell_2.g.$(OBJEXT)          $(libraries)
 find_cell_3.exe         : find_cell_3.g.$(OBJEXT)          $(libraries)
 sparse_matrix_01.exe    : sparse_matrix_01.g.$(OBJEXT)     $(libraries)
+sparse_matrix_01a.exe   : sparse_matrix_01a.g.$(OBJEXT)    $(libraries)
 sparse_matrix_02.exe    : sparse_matrix_02.g.$(OBJEXT)     $(libraries)
 sparse_matrix_03.exe    : sparse_matrix_03.g.$(OBJEXT)     $(libraries)
 sparse_matrix_04.exe    : sparse_matrix_04.g.$(OBJEXT)     $(libraries)
@@ -201,6 +202,7 @@ tests = anna_1 anna_2 anna_3 anna_4 anna_5 anna_6 \
        mapping_cartesian_1 \
        mapping_q4_3d \
        q_points find_cell_1 find_cell_2 find_cell_3 \
+        sparse_matrix_01a \
         sparse_matrix_01 sparse_matrix_02 sparse_matrix_03 \
         sparse_matrix_04 sparse_matrix_05 sparse_matrix_05a \
        sparse_matrix_06 \
diff --git a/tests/bits/sparse_matrix_01a.cc b/tests/bits/sparse_matrix_01a.cc
new file mode 100644 (file)
index 0000000..63bfb14
--- /dev/null
@@ -0,0 +1,105 @@
+//----------------------------  sparse_matrix_01a.cc  ---------------------------
+//    sparse_matrix_01.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  sparse_matrix_01a.cc  ---------------------------
+
+
+// check setting elements in a sparse matrix using SparseMatrix::set(). make
+// sure they are correct, and make sure that for the nonexisting entries
+// SparseMatrix::el() returns zero and operator() throws an exception
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3,false);
+  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 ();
+
+  SparseMatrix<double> m(sp);
+  
+                                   // first set a few entries
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        m.set (i,j, i*j*.5+.5);
+
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+          Assert (m.el(i,j) == i*j*.5+.5, ExcInternalError());
+        }
+      else
+        {
+          Assert (m.el(i,j) == 0, ExcInternalError());
+          bool exc_thrown = false;
+          double d;
+          try
+            {
+              d = m(i,j);
+            }
+          catch (const std::exception &)
+            {
+              exc_thrown = true;
+            }
+          Assert (exc_thrown == true, ExcInternalError());
+        }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_01a.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}

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.