Tpetra parallel linear algebra  Version of the Day
Tpetra_MultiVectorFiller.cpp
1 #include <Tpetra_MultiVectorFiller.hpp>
2 
3 namespace Tpetra {
4  namespace Test {
5 
6  void
7  testSortAndMergeIn ()
8  {
9  using Teuchos::Array;
10  using Teuchos::ArrayView;
11  using Tpetra::Details::sortAndMergeIn;
12 
13  Array<int> allEntries (5);
14  for (Array<int>::size_type k = 0; k < 5; ++k) {
15  allEntries[k] = 2 * k;
16  }
17  Array<int> newEntries (4);
18  newEntries[0] = -1;
19  newEntries[1] = 3;
20  newEntries[2] = 3;
21  newEntries[3] = 11;
22 
23  ArrayView<int> result =
24  sortAndMergeIn<int> (allEntries, allEntries.view (0, 5), newEntries());
25  TEUCHOS_TEST_FOR_EXCEPTION(
26  result.size() != 8, std::logic_error,
27  "Returned ArrayView should have size 8, but instead has size "
28  << result.size() << ".");
29  TEUCHOS_TEST_FOR_EXCEPTION(
30  allEntries.size() < 8, std::logic_error,
31  "Input/output Array argument should have size at least 8, but instead has "
32  "size " << allEntries.size() << ".");
33 
34  bool success = true;
35  ArrayView<int>::size_type firstBadIndex = -1; // size_type is signed
36  for (ArrayView<int>::size_type k = 0; k < result.size(); ++k) {
37  if (result[k] != allEntries[k]) {
38  success = false;
39  firstBadIndex = k;
40  break;
41  }
42  }
43  TEUCHOS_TEST_FOR_EXCEPTION(
44  success, std::logic_error, "Returned ArrayView and the input/output "
45  "Array argument don't match. First nonmatching array index is "
46  << firstBadIndex << ".");
47 
48  Array<int> expectedEntries (8);
49  expectedEntries[0] = -1;
50  expectedEntries[1] = 0;
51  expectedEntries[2] = 2;
52  expectedEntries[3] = 3;
53  expectedEntries[4] = 4;
54  expectedEntries[5] = 6;
55  expectedEntries[6] = 8;
56  expectedEntries[7] = 11;
57  for (ArrayView<int>::size_type k = 0; k < result.size(); ++k) {
58  if (expectedEntries[k] != result[k]) {
59  success = false;
60  firstBadIndex = k;
61  break;
62  }
63  }
64  TEUCHOS_TEST_FOR_EXCEPTION(success, std::logic_error, "Returned ArrayView "
65  "and the expected results don't match. First nonmatching array index is "
66  << firstBadIndex << ".");
67  }
68 
69  } // namespace Test
70 } // namespace Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.