|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // Teuchos: Common Tools Package 00006 // Copyright (2004) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 */ 00043 00044 #include "Teuchos_UnitTestHarness.hpp" 00045 #include "Teuchos_Array.hpp" 00046 #include "Teuchos_getConst.hpp" 00047 #include "Teuchos_as.hpp" 00048 00049 00050 namespace { 00051 00052 00053 int n = 4; 00054 00055 00056 TEUCHOS_STATIC_SETUP() 00057 { 00058 Teuchos::UnitTestRepository::getCLP().setOption( 00059 "n", &n, "Number of elements in the vectors" ); 00060 } 00061 00062 00063 template<class T> 00064 std::vector<T> generatevector(const int n_in) 00065 { 00066 using Teuchos::as; 00067 std::vector<T> a(n_in); 00068 for( int i = 0; i < n_in; ++i ) 00069 a[i] = as<T>(i); // tests non-const operator[](i) 00070 return a; 00071 } 00072 00073 00074 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, defaultConstruct, T ) 00075 { 00076 using std::vector; 00077 using Teuchos::as; 00078 vector<T> a2; 00079 TEST_EQUALITY_CONST( as<int>(a2.size()), 0 ); 00080 TEST_EQUALITY_CONST( a2.empty(), true ); 00081 } 00082 00083 00084 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, sizedConstruct, T ) 00085 { 00086 using std::vector; 00087 using Teuchos::as; 00088 using Teuchos::getConst; 00089 typedef typename std::vector<T>::size_type size_type; 00090 vector<T> a(n); 00091 TEST_EQUALITY_CONST( a.empty(), false ); 00092 TEST_EQUALITY( as<int>(a.size()), n ); 00093 TEST_COMPARE( a.max_size(), >=, as<size_type>(n) ); 00094 TEST_COMPARE( as<int>(a.capacity()), >=, n ); 00095 } 00096 00097 00098 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, operatorBracket, T ) 00099 { 00100 using std::vector; 00101 using Teuchos::as; 00102 out << "\nTest that a[i] == i ... "; 00103 vector<T> a = generatevector<T>(n);; 00104 bool local_success = true; 00105 for( int i = 0; i < n; ++i ) { 00106 TEST_ARRAY_ELE_EQUALITY( a, i, as<T>(i) ); 00107 } 00108 if (local_success) out << "passed\n"; 00109 else success = false; 00110 } 00111 00112 00113 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, constAt, T ) 00114 { 00115 using std::vector; 00116 using Teuchos::as; 00117 out << "\nTest that a.at(i) == i ...\n"; 00118 vector<T> a = generatevector<T>(n);; 00119 bool local_success = true; 00120 for( int i = 0; i < n; ++i ) { 00121 TEUCHOS_TEST_EQUALITY( a.at(i), as<T>(i), out, local_success ); 00122 } 00123 if (local_success) out << "passed\n"; 00124 else success = false; 00125 } 00126 00127 00128 // 00129 // Instantiations 00130 // 00131 00132 00133 #define UNIT_TEST_GROUP( T ) \ 00134 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, defaultConstruct, T ) \ 00135 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, sizedConstruct, T ) \ 00136 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, operatorBracket, T ) \ 00137 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, constAt, T ) 00138 00139 00140 UNIT_TEST_GROUP(int) 00141 UNIT_TEST_GROUP(float) 00142 UNIT_TEST_GROUP(double) 00143 00144 00145 } // namespace
1.7.6.1