From 096ca20218c79e0cd2c07e0a213b32d826bf3de5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 29 Mar 2004 19:45:48 +0000 Subject: [PATCH] New tests. git-svn-id: https://svn.dealii.org/trunk@8891 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/sparse_matrix_iterator_02.cc | 91 +++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_03.cc | 91 +++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_04.cc | 90 +++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_05.cc | 97 +++++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_06.cc | 97 +++++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_07.cc | 97 +++++++++++++++++++++++++ tests/bits/sparse_matrix_iterator_08.cc | 97 +++++++++++++++++++++++++ 7 files changed, 660 insertions(+) create mode 100644 tests/bits/sparse_matrix_iterator_02.cc create mode 100644 tests/bits/sparse_matrix_iterator_03.cc create mode 100644 tests/bits/sparse_matrix_iterator_04.cc create mode 100644 tests/bits/sparse_matrix_iterator_05.cc create mode 100644 tests/bits/sparse_matrix_iterator_06.cc create mode 100644 tests/bits/sparse_matrix_iterator_07.cc create mode 100644 tests/bits/sparse_matrix_iterator_08.cc diff --git a/tests/bits/sparse_matrix_iterator_02.cc b/tests/bits/sparse_matrix_iterator_02.cc new file mode 100644 index 0000000000..a78f878bfc --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_02.cc @@ -0,0 +1,91 @@ +//---------------------------- sparse_matrix_iterator_02.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_02.cc --------------------------- + + +// test setting some elements and reading them back from a const matrix +// iterator + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set (i,j, i*j); + + SparseMatrix::const_iterator i = m.begin(); + for (; i!=m.end(); ++i) + { + deallog << i->row() << ' ' << i->column() << ' ' + << i->value() << std::endl; + Assert (std::fabs(i->value() - i->row()*i->column()) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_02.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_iterator_03.cc b/tests/bits/sparse_matrix_iterator_03.cc new file mode 100644 index 0000000000..0a414587b1 --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_03.cc @@ -0,0 +1,91 @@ +//---------------------------- sparse_matrix_iterator_03.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_03.cc --------------------------- + + +// test setting some elements and reading them back from a non-const matrix +// iterator + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set (i,j, i*j); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + { + deallog << i->row() << ' ' << i->column() << ' ' + << i->value() << std::endl; + Assert (std::fabs(i->value() - i->row()*i->column()) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_03.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_iterator_04.cc b/tests/bits/sparse_matrix_iterator_04.cc new file mode 100644 index 0000000000..bb20ceb262 --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_04.cc @@ -0,0 +1,90 @@ +//---------------------------- sparse_matrix_iterator_04.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_04.cc --------------------------- + +// test setting some elements using a non-const matrix iterator and operator=, +// and reading them back through the matrix itself + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + SparseMatrix m(sp); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + i->value() = i->row()*i->column(); + + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + { + deallog << i << ' ' << j << ' ' << m.el(i,j) + << std::endl; + Assert (std::fabs(m.el(i,j)-i*j) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_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_iterator_05.cc b/tests/bits/sparse_matrix_iterator_05.cc new file mode 100644 index 0000000000..2030ac6f41 --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_05.cc @@ -0,0 +1,97 @@ +//---------------------------- sparse_matrix_iterator_05.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_05.cc --------------------------- + +// test setting some elements using a non-const matrix iterator and operator+=, +// and reading them back through the matrix itself + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set(i,j,1.); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + i->value() += i->row()*i->column(); + + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + { + deallog << i << ' ' << j << ' ' << m.el(i,j) + << std::endl; + Assert (std::fabs(m.el(i,j)-(1.+i*j)) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_05.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_iterator_06.cc b/tests/bits/sparse_matrix_iterator_06.cc new file mode 100644 index 0000000000..6dffa4d38e --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_06.cc @@ -0,0 +1,97 @@ +//---------------------------- sparse_matrix_iterator_06.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_06.cc --------------------------- + +// test setting some elements using a non-const matrix iterator and operator-=, +// and reading them back through the matrix itself + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set(i,j,1.); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + i->value() -= i->row()*i->column(); + + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + { + deallog << i << ' ' << j << ' ' << m.el(i,j) + << std::endl; + Assert (std::fabs(m.el(i,j)-(1.-i*j)) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_06.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_iterator_07.cc b/tests/bits/sparse_matrix_iterator_07.cc new file mode 100644 index 0000000000..a0963b04c2 --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_07.cc @@ -0,0 +1,97 @@ +//---------------------------- sparse_matrix_iterator_07.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_07.cc --------------------------- + +// test setting some elements using a non-const matrix iterator and operator*=, +// and reading them back through the matrix itself + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set(i,j,i*j); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + i->value() *= 2; + + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + { + deallog << i << ' ' << j << ' ' << m.el(i,j) + << std::endl; + Assert (std::fabs(m.el(i,j)-(2.*i*j)) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_07.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_iterator_08.cc b/tests/bits/sparse_matrix_iterator_08.cc new file mode 100644 index 0000000000..7767c4e110 --- /dev/null +++ b/tests/bits/sparse_matrix_iterator_08.cc @@ -0,0 +1,97 @@ +//---------------------------- sparse_matrix_iterator_08.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 by the deal.II authors +// +// 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_iterator_08.cc --------------------------- + +// test setting some elements using a non-const matrix iterator and operator/=, +// and reading them back through the matrix itself + +#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) + || + (i==j)) + sp.add (i,j); + sp.compress (); + + SparseMatrix m(sp); + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + m.set(i,j,i*j); + + SparseMatrix::iterator i = m.begin(); + for (; i!=m.end(); ++i) + i->value() /= 2; + + for (unsigned int i=0; i<5; ++i) + for (unsigned int j=0; j<5; ++j) + if (((i+2*j+1) % 3 == 0) + || + (i==j)) + { + deallog << i << ' ' << j << ' ' << m.el(i,j) + << std::endl; + Assert (std::fabs(m.el(i,j)-(i*j/2.)) < 1e-14, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("sparse_matrix_iterator_08.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; + }; +} -- 2.39.5