From 4bcafcf508904fa2320bfae35137118e95b3eac0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 24 Aug 2023 18:11:19 -0600 Subject: [PATCH] Add a test. --- tests/base/index_set_34.cc | 66 ++++++++++++++++++++++++++++++++++ tests/base/index_set_34.output | 2 ++ 2 files changed, 68 insertions(+) create mode 100644 tests/base/index_set_34.cc create mode 100644 tests/base/index_set_34.output 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 -- 2.39.5