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