|
Tpetra Matrix/Vector Services
Version of the Day
|
00001 #include <Tpetra_MultiVectorFiller.hpp> 00002 00003 namespace Tpetra { 00004 namespace Test { 00005 00006 void 00007 testSortAndMergeIn () 00008 { 00009 using Teuchos::Array; 00010 using Teuchos::ArrayView; 00011 using Tpetra::Details::sortAndMergeIn; 00012 00013 Array<int> allEntries (5); 00014 for (Array<int>::size_type k = 0; k < 5; ++k) { 00015 allEntries[k] = 2 * k; 00016 } 00017 Array<int> newEntries (4); 00018 newEntries[0] = -1; 00019 newEntries[1] = 3; 00020 newEntries[2] = 3; 00021 newEntries[3] = 11; 00022 00023 ArrayView<int> result = 00024 sortAndMergeIn<int> (allEntries, allEntries.view (0, 5), newEntries()); 00025 TEUCHOS_TEST_FOR_EXCEPTION( 00026 result.size() != 8, std::logic_error, 00027 "Returned ArrayView should have size 8, but instead has size " 00028 << result.size() << "."); 00029 TEUCHOS_TEST_FOR_EXCEPTION( 00030 allEntries.size() < 8, std::logic_error, 00031 "Input/output Array argument should have size at least 8, but instead has " 00032 "size " << allEntries.size() << "."); 00033 00034 bool success = true; 00035 ArrayView<int>::size_type firstBadIndex = -1; // size_type is signed 00036 for (ArrayView<int>::size_type k = 0; k < result.size(); ++k) { 00037 if (result[k] != allEntries[k]) { 00038 success = false; 00039 firstBadIndex = k; 00040 break; 00041 } 00042 } 00043 TEUCHOS_TEST_FOR_EXCEPTION( 00044 success, std::logic_error, "Returned ArrayView and the input/output " 00045 "Array argument don't match. First nonmatching array index is " 00046 << firstBadIndex << "."); 00047 00048 Array<int> expectedEntries (8); 00049 expectedEntries[0] = -1; 00050 expectedEntries[1] = 0; 00051 expectedEntries[2] = 2; 00052 expectedEntries[3] = 3; 00053 expectedEntries[4] = 4; 00054 expectedEntries[5] = 6; 00055 expectedEntries[6] = 8; 00056 expectedEntries[7] = 11; 00057 for (ArrayView<int>::size_type k = 0; k < result.size(); ++k) { 00058 if (expectedEntries[k] != result[k]) { 00059 success = false; 00060 firstBadIndex = k; 00061 break; 00062 } 00063 } 00064 TEUCHOS_TEST_FOR_EXCEPTION(success, std::logic_error, "Returned ArrayView " 00065 "and the expected results don't match. First nonmatching array index is " 00066 << firstBadIndex << "."); 00067 } 00068 00069 } // namespace Test 00070 } // namespace Tpetra
1.7.6.1