From dcc7ae816d9e25090f3595fb0fd85f875c5017cb Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 6 Feb 2004 19:46:57 +0000 Subject: [PATCH] New unit tests. git-svn-id: https://svn.dealii.org/trunk@8411 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/sparse_matrix_01.cc | 94 +++++++++++++++++++++++++++++++ tests/bits/sparse_matrix_02.cc | 93 ++++++++++++++++++++++++++++++ tests/bits/sparse_matrix_03.cc | 100 +++++++++++++++++++++++++++++++++ tests/bits/sparse_matrix_04.cc | 75 +++++++++++++++++++++++++ tests/bits/sparse_matrix_05.cc | 88 +++++++++++++++++++++++++++++ tests/bits/sparse_matrix_06.cc | 84 +++++++++++++++++++++++++++ tests/bits/sparse_matrix_07.cc | 84 +++++++++++++++++++++++++++ tests/bits/sparse_matrix_08.cc | 89 +++++++++++++++++++++++++++++ tests/bits/sparse_matrix_09.cc | 96 +++++++++++++++++++++++++++++++ tests/bits/sparse_matrix_10.cc | 96 +++++++++++++++++++++++++++++++ 10 files changed, 899 insertions(+) create mode 100644 tests/bits/sparse_matrix_01.cc create mode 100644 tests/bits/sparse_matrix_02.cc create mode 100644 tests/bits/sparse_matrix_03.cc create mode 100644 tests/bits/sparse_matrix_04.cc create mode 100644 tests/bits/sparse_matrix_05.cc create mode 100644 tests/bits/sparse_matrix_06.cc create mode 100644 tests/bits/sparse_matrix_07.cc create mode 100644 tests/bits/sparse_matrix_08.cc create mode 100644 tests/bits/sparse_matrix_09.cc create mode 100644 tests/bits/sparse_matrix_10.cc diff --git a/tests/bits/sparse_matrix_01.cc b/tests/bits/sparse_matrix_01.cc new file mode 100644 index 0000000000..37f3443c01 --- /dev/null +++ b/tests/bits/sparse_matrix_01.cc @@ -0,0 +1,94 @@ +//---------------------------- sparse_matrix_01.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_01.cc --------------------------- + + +// check setting elements in a sparse matrix using +// SparseMatrix::set() + +#include "../tests.h" +#include +#include +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + Assert (m.m() == 5, ExcInternalError()); + Assert (m.n() == 5, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_04.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; + }; +} diff --git a/tests/bits/sparse_matrix_05.cc b/tests/bits/sparse_matrix_05.cc new file mode 100644 index 0000000000..45a6cc202d --- /dev/null +++ b/tests/bits/sparse_matrix_05.cc @@ -0,0 +1,88 @@ +//---------------------------- sparse_matrix_05.cc --------------------------- +// sparse_matrix_05.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_05.cc --------------------------- + + +// check querying the number of nonzero elements in +// SparseMatrix + +#include "../tests.h" +#include +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries. count how many + // entries we have + unsigned int counter = 0; + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries. count how many + // entries we have + double norm = 0; + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries + for (unsigned int i=0; i +#include + + +void test () +{ + SparsityPattern sp (5,5,3); + 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 m(sp); + + // first set a few entries + for (unsigned int i=0; i