--- /dev/null
+//-----------------------------------------------------------------------------
+// $Id: index_set_19.cc 23710 2011-05-17 04:50:10Z bangerth $
+// Version: $Name$
+//
+// Copyright (C) 2010 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// test IndexSet::add_indices(IndexSet)
+
+#include "../tests.h"
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <stdlib.h>
+
+#include <deal.II/base/index_set.h>
+
+void testor(IndexSet & a, IndexSet & other, bool verbose=true)
+{
+ IndexSet merged(a);
+
+ merged.add_indices(other);
+
+ if (verbose)
+ {
+ deallog << "Original index set: " << std::endl;
+ a.print(deallog);
+ deallog << "other index set: " << std::endl;
+ other.print(deallog);
+ deallog << "merged index set: " << std::endl;
+ merged.print(deallog);
+ }
+
+ for (unsigned int i=0;i<merged.size();++i)
+ {
+ Assert(
+ merged.is_element(i)
+ ==
+ (a.is_element(i) || other.is_element(i)),
+ ExcInternalError());
+ }
+}
+
+
+
+
+void test()
+{
+ const int size = 10;
+
+ IndexSet empty(size);
+ IndexSet id(size);
+
+ id.add_index(3);
+ id.add_index(4);
+ id.add_index(7);
+
+ deallog << "* add empty: " << std::endl;
+ testor(id, empty);
+
+ deallog << "* add self: " << std::endl;
+ testor(id, id);
+
+ deallog << "* add id2: " << std::endl;
+ IndexSet id2(size);
+ id2.add_index(0);
+ id2.add_index(2);
+ id2.add_index(3);
+ testor(id, id2);
+
+ deallog << "* random tests... " << std::endl;
+ for (unsigned int i=0;i<10;++i)
+ {
+ const int size=100;
+ IndexSet a(size);
+ IndexSet b(size);
+ for (unsigned int i=0; i<9*a.size()/10; ++i)
+ {
+ a.add_index (rand() % a.size());
+ b.add_index (rand() % a.size());
+ }
+ testor(a, b, false);
+ }
+}
+
+
+
+
+
+
+int main()
+{
+ std::ofstream logfile("index_set_20/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}
--- /dev/null
+
+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::List of indices:
+DEAL::2 3 5 8 11 13 14 15 19 21 22 23 24 25 26 27 29 30 34 35 36 37 40 42 43 45 46 49 50 51 54 56 57 58 59 62 63 64 67 68 69 70 72 73 76 77 78 80 81 82 83 84 86 87 88 90 91 92 93 95 96 98 99
+DEAL::OK