From: Wolfgang Bangerth Date: Fri, 25 Aug 2023 00:11:19 +0000 (-0600) Subject: Add a test. X-Git-Tag: relicensing~549^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bcafcf508904fa2320bfae35137118e95b3eac0;p=dealii.git Add a test. --- diff --git a/tests/base/index_set_34.cc b/tests/base/index_set_34.cc new file mode 100644 index 0000000000..69b870b11f --- /dev/null +++ b/tests/base/index_set_34.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 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::is_subset_of() + +#include + +#include "../tests.h" + + +void +test() +{ + // Create an index set that has about 30% of its possible indices: + const unsigned int N = 1000; + IndexSet index_set(N); + for (unsigned int i = 0; i < N / 3; ++i) + index_set.add_index(random_value(0, N - 1)); + index_set.compress(); + + // Test that the set is a subset of itself: + Assert(index_set.is_subset_of(index_set), ExcInternalError()); + + // Now take out one value after the other in some random order, and + // make sure that the result is a subset of the original set (and + // that the original one is *not* a subset (because it must be a + // superset): + const IndexSet original = index_set; + while (index_set.is_empty() == false) + { + IndexSet to_remove(N); + to_remove.add_index(index_set.nth_index_in_set( + random_value(0, index_set.n_elements() - 1))); + to_remove.compress(); + + index_set.subtract_set(to_remove); + + Assert(index_set.is_subset_of(original) == true, ExcInternalError()); + Assert(original.is_subset_of(index_set) == false, ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/base/index_set_34.output b/tests/base/index_set_34.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/index_set_34.output @@ -0,0 +1,2 @@ + +DEAL::OK