]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 2 Oct 2023 17:52:42 +0000 (11:52 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 5 Oct 2023 02:38:00 +0000 (20:38 -0600)
tests/base/index_set_36.cc [new file with mode: 0644]
tests/base/index_set_36.output [new file with mode: 0644]
tests/base/index_set_37.cc [new file with mode: 0644]
tests/base/index_set_37.output [new file with mode: 0644]
tests/base/index_set_38.cc [new file with mode: 0644]
tests/base/index_set_38.output [new file with mode: 0644]

diff --git a/tests/base/index_set_36.cc b/tests/base/index_set_36.cc
new file mode 100644 (file)
index 0000000..e8ccab3
--- /dev/null
@@ -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 <deal.II/base/index_set.h>
+
+#include <stdlib.h>
+
+#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 (file)
index 0000000..d7c72c7
--- /dev/null
@@ -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 (file)
index 0000000..0594a57
--- /dev/null
@@ -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 <deal.II/base/index_set.h>
+
+#include <stdlib.h>
+
+#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 (file)
index 0000000..ada77c2
--- /dev/null
@@ -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 (file)
index 0000000..8178123
--- /dev/null
@@ -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 <deal.II/base/index_set.h>
+
+#include <stdlib.h>
+
+#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 (file)
index 0000000..0fd8930
--- /dev/null
@@ -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

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.