]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 25 Aug 2023 00:11:19 +0000 (18:11 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 25 Aug 2023 00:12:17 +0000 (18:12 -0600)
tests/base/index_set_34.cc [new file with mode: 0644]
tests/base/index_set_34.output [new file with mode: 0644]

diff --git a/tests/base/index_set_34.cc b/tests/base/index_set_34.cc
new file mode 100644 (file)
index 0000000..69b870b
--- /dev/null
@@ -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 <deal.II/base/index_set.h>
+
+#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<unsigned int>(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<unsigned int>(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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.