From: Wolfgang Bangerth Date: Mon, 13 Apr 2015 13:51:10 +0000 (-0500) Subject: Add tests for iterators over DynamicSparsityPattern objects. X-Git-Tag: v8.3.0-rc1~280^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=325cf894699b99ca0dd9a0be65b9dd3d043d5b1c;p=dealii.git Add tests for iterators over DynamicSparsityPattern objects. --- diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_01.cc b/tests/bits/dynamic_sparsity_pattern_iterator_01.cc new file mode 100644 index 0000000000..becd8af92e --- /dev/null +++ b/tests/bits/dynamic_sparsity_pattern_iterator_01.cc @@ -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 +#include +#include + + +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 index 0000000000..3f3197a695 --- /dev/null +++ b/tests/bits/dynamic_sparsity_pattern_iterator_01.output @@ -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 index 0000000000..1c58e9969d --- /dev/null +++ b/tests/bits/dynamic_sparsity_pattern_iterator_02.cc @@ -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 +#include +#include + + +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 index 0000000000..517e23fc09 --- /dev/null +++ b/tests/bits/dynamic_sparsity_pattern_iterator_02.output @@ -0,0 +1,6 @@ + +DEAL::0 0 +DEAL::3 3 +DEAL::OK +DEAL::3 3 +DEAL::OK