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