|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "Teuchos_UnitTestHarness.hpp" 00043 #include "Teuchos_TwoDArray.hpp" 00044 00045 00046 00047 namespace Teuchos{ 00048 00049 TwoDArray<int> getSimpleTestTwoDArray(){ 00050 TwoDArray<int> simpleArray(2,2); 00051 simpleArray(0,0) =1; 00052 simpleArray(0,1) =2; 00053 simpleArray(1,0) =3; 00054 simpleArray(1,1) =4; 00055 return simpleArray; 00056 } 00057 00058 00062 TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, simpleTest){ 00063 TwoDArray<int> simpleArray(3,2); 00064 simpleArray[0][0] =1; 00065 simpleArray[0][1] =2; 00066 simpleArray[1][0] =3; 00067 simpleArray[1][1] =4; 00068 simpleArray[2][0] =5; 00069 simpleArray[2][1] =6; 00070 TEST_EQUALITY_CONST(simpleArray[0][0],1) 00071 TEST_EQUALITY_CONST(simpleArray[0][1],2) 00072 TEST_EQUALITY_CONST(simpleArray[1][0],3) 00073 TEST_EQUALITY_CONST(simpleArray[1][1],4) 00074 TEST_EQUALITY_CONST(simpleArray[2][0],5) 00075 TEST_EQUALITY_CONST(simpleArray[2][1],6) 00076 00077 TEST_EQUALITY_CONST(simpleArray(0,0),1) 00078 TEST_EQUALITY_CONST(simpleArray(0,1),2) 00079 TEST_EQUALITY_CONST(simpleArray(1,0),3) 00080 TEST_EQUALITY_CONST(simpleArray(1,1),4) 00081 TEST_EQUALITY_CONST(simpleArray(2,0),5) 00082 TEST_EQUALITY_CONST(simpleArray(2,1),6) 00083 00084 TEST_EQUALITY_CONST(simpleArray.getNumRows(), 3) 00085 TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2) 00086 Array<int> oneDArray = tuple<int>(1,2,3,4,5,6); 00087 TEST_COMPARE_ARRAYS(oneDArray, simpleArray.getDataArray()) 00088 00089 } 00090 00091 TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, stringFunctions){ 00092 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00093 std::string stringRep = TwoDArray<int>::toString(simpleArray); 00094 TwoDArray<int> convertedArray = TwoDArray<int>::fromString(stringRep); 00095 TEST_EQUALITY(simpleArray, convertedArray) 00096 00097 std::string badStringRep = "4x4:{1.0,1.0}"; 00098 TEST_THROW(TwoDArray<int>::fromString(badStringRep), 00099 InvalidArrayStringRepresentation) 00100 } 00101 00102 TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, emptyTest){ 00103 TwoDArray<int> emptyArray; 00104 TEST_EQUALITY_CONST(emptyArray.getNumRows(), 0) 00105 TEST_EQUALITY_CONST(emptyArray.getNumCols(), 0) 00106 TEST_EQUALITY_CONST(emptyArray.getDataArray().size(), 0) 00107 TEST_ASSERT(emptyArray.isEmpty()); 00108 } 00109 00110 TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, streamTests){ 00111 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00112 std::stringstream ss; 00113 ss << simpleArray; 00114 TwoDArray<int> readArray; 00115 std::istringstream instream(ss.str()); 00116 instream >> readArray; 00117 TEST_EQUALITY(simpleArray, readArray); 00118 } 00119 00120 TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, clearTest){ 00121 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00122 00123 simpleArray.clear(); 00124 TEST_ASSERT(simpleArray.isEmpty()); 00125 } 00126 00127 TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, resizeTest){ 00128 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00129 00130 simpleArray.resizeRows(4); 00131 TEST_EQUALITY_CONST(simpleArray.getNumRows(), 4); 00132 TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); 00133 TEST_EQUALITY_CONST(simpleArray(3,1), 0); 00134 TEST_EQUALITY_CONST(simpleArray(1,1), 4); 00135 00136 simpleArray.resizeRows(2); 00137 TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); 00138 TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); 00139 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00140 TEST_THROW(simpleArray(3,1), RangeError); 00141 #endif 00142 TEST_EQUALITY_CONST(simpleArray(1,1), 4); 00143 00144 simpleArray.resizeCols(4); 00145 TEST_EQUALITY_CONST(simpleArray.getNumCols(), 4); 00146 TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); 00147 TEST_EQUALITY_CONST(simpleArray(1,3), 0); 00148 TEST_EQUALITY_CONST(simpleArray(1,1), 4); 00149 00150 simpleArray.resizeCols(2); 00151 TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); 00152 TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); 00153 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00154 TEST_THROW(simpleArray(1,3), RangeError); 00155 #endif 00156 TEST_EQUALITY_CONST(simpleArray(1,1), 4); 00157 00158 } 00159 00160 TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, symmetryTest){ 00161 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00162 TEST_ASSERT(!simpleArray.isSymmetrical()); 00163 simpleArray.setSymmetrical(true); 00164 TEST_ASSERT(simpleArray.isSymmetrical()); 00165 00166 } 00167 00168 TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, symmetrySerialization){ 00169 TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); 00170 simpleArray.setSymmetrical(true); 00171 std::string arrayString = TwoDArray<int>::toString(simpleArray); 00172 TwoDArray<int> readIn = TwoDArray<int>::fromString(arrayString); 00173 TEST_ASSERT(readIn.isSymmetrical()); 00174 } 00175 00176 00177 } //namespace Teuchos 00178
1.7.6.1