From aeeae36e1dec95d070a0634e63ab37b0f9be31e3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 2 Oct 2023 11:52:42 -0600 Subject: [PATCH] Add tests. --- tests/base/index_set_36.cc | 63 +++++++++++++++++++++++++++++++++ tests/base/index_set_36.output | 6 ++++ tests/base/index_set_37.cc | 64 ++++++++++++++++++++++++++++++++++ tests/base/index_set_37.output | 8 +++++ tests/base/index_set_38.cc | 64 ++++++++++++++++++++++++++++++++++ tests/base/index_set_38.output | 8 +++++ 6 files changed, 213 insertions(+) create mode 100644 tests/base/index_set_36.cc create mode 100644 tests/base/index_set_36.output create mode 100644 tests/base/index_set_37.cc create mode 100644 tests/base/index_set_37.output create mode 100644 tests/base/index_set_38.cc create mode 100644 tests/base/index_set_38.output diff --git a/tests/base/index_set_36.cc b/tests/base/index_set_36.cc new file mode 100644 index 0000000000..e8ccab3975 --- /dev/null +++ b/tests/base/index_set_36.cc @@ -0,0 +1,63 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// test IndexSet::get_view(IndexSet) with a mask that is identical to +// the one used in the _18 test just that it is given as an IndexSet +// rather than a single range. + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + IndexSet is1(100); + + // randomly add 90 elements to each + // set, some of which may be + // repetitions of previous ones + for (unsigned int i = 0; i < 9 * is1.size() / 10; ++i) + is1.add_index(Testing::rand() % is1.size()); + + is1.compress(); + + IndexSet mask(100); + mask.add_range(20, 50); + + const IndexSet is2 = is1.get_view(mask); + Assert(is2.size() == mask.n_elements(), ExcInternalError()); + + deallog << "Original index set: " << std::endl; + is1.print(deallog); + deallog << "View of index set between 20 and 50: " << std::endl; + is2.print(deallog); + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/base/index_set_36.output b/tests/base/index_set_36.output new file mode 100644 index 0000000000..d7c72c7ae3 --- /dev/null +++ b/tests/base/index_set_36.output @@ -0,0 +1,6 @@ + +DEAL::Original index set: +DEAL::{[2,3], 5, 8, 11, [13,15], 19, [21,27], [29,30], [34,37], 40, [42,43], [45,46], [49,51], 54, [56,59], [62,64], [67,70], [72,73], [76,78], [80,84], [86,88], [90,93], [95,96], [98,99]} +DEAL::View of index set between 20 and 50: +DEAL::{[1,7], [9,10], [14,17], 20, [22,23], [25,26], 29} +DEAL::OK diff --git a/tests/base/index_set_37.cc b/tests/base/index_set_37.cc new file mode 100644 index 0000000000..0594a5716f --- /dev/null +++ b/tests/base/index_set_37.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// test IndexSet::get_view(IndexSet) with a mask that is not just a +// single range. + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + IndexSet is1(100); + + // randomly add 90 elements to each + // set, some of which may be + // repetitions of previous ones + for (unsigned int i = 0; i < 9 * is1.size() / 10; ++i) + is1.add_index(Testing::rand() % is1.size()); + + IndexSet mask(100); + mask.add_range(20, 40); + mask.add_range(60, 80); + mask.compress(); + + const IndexSet is2 = is1.get_view(mask); + Assert(is2.size() == mask.n_elements(), ExcInternalError()); + + deallog << "Original index set: " << std::endl; + is1.print(deallog); + deallog << "Mask: " << std::endl; + mask.print(deallog); + deallog << "View of index set between 20-40 and 60-80: " << std::endl; + is2.print(deallog); + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/base/index_set_37.output b/tests/base/index_set_37.output new file mode 100644 index 0000000000..ada77c2ba2 --- /dev/null +++ b/tests/base/index_set_37.output @@ -0,0 +1,8 @@ + +DEAL::Original index set: +DEAL::{[2,3], 5, 8, 11, [13,15], 19, [21,27], [29,30], [34,37], 40, [42,43], [45,46], [49,51], 54, [56,59], [62,64], [67,70], [72,73], [76,78], [80,84], [86,88], [90,93], [95,96], [98,99]} +DEAL::Mask: +DEAL::{[20,39], [60,79]} +DEAL::View of index set between 20-40 and 60-80: +DEAL::{[1,7], [9,10], [14,17], [22,24], [27,30], [32,33], [36,38]} +DEAL::OK diff --git a/tests/base/index_set_38.cc b/tests/base/index_set_38.cc new file mode 100644 index 0000000000..81781231d3 --- /dev/null +++ b/tests/base/index_set_38.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Test IndexSet::get_view(IndexSet) with a mask that is not just a +// single range. +// +// This test is for the specific example given in the documentation of +// the function we test. + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + IndexSet is1(100); + is1.add_range(20, 40); + is1.compress(); + + IndexSet mask(100); + for (unsigned int i = 0; i < is1.size(); ++i) + if (i % 2 == 1) + mask.add_index(i); + mask.compress(); + + const IndexSet is2 = is1.get_view(mask); + Assert(is2.size() == mask.n_elements(), ExcInternalError()); + + deallog << "Original index set: " << std::endl; + is1.print(deallog); + deallog << "Mask: " << std::endl; + mask.print(deallog); + deallog << "View of index set among the odd numbers: " << std::endl; + is2.print(deallog); + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/base/index_set_38.output b/tests/base/index_set_38.output new file mode 100644 index 0000000000..0fd89305c9 --- /dev/null +++ b/tests/base/index_set_38.output @@ -0,0 +1,8 @@ + +DEAL::Original index set: +DEAL::{[20,39]} +DEAL::Mask: +DEAL::{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99} +DEAL::View of index set among the odd numbers: +DEAL::{[11,20]} +DEAL::OK -- 2.39.5