vector_UnitTests.cpp

Go to the documentation of this file.
00001 #include "Teuchos_UnitTestHarness.hpp"
00002 #include "Teuchos_Array.hpp"
00003 #include "Teuchos_getConst.hpp"
00004 #include "Teuchos_as.hpp"
00005 
00006 
00007 namespace {
00008 
00009 
00010 int n = 4;
00011 
00012 
00013 TEUCHOS_STATIC_SETUP()
00014 {
00015   Teuchos::UnitTestRepository::getCLP().setOption(
00016     "n", &n, "Number of elements in the vectors" );
00017 }
00018 
00019 
00020 template<class T>
00021 std::vector<T> generatevector(const int n_in)
00022 {
00023   using Teuchos::as;
00024   std::vector<T> a(n_in);
00025   for( int i = 0; i < n_in; ++i )
00026     a[i] = as<T>(i); // tests non-const operator[](i)
00027   return a;
00028 }
00029 
00030 
00031 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, defaultConstruct, T )
00032 {
00033   using std::vector;
00034   using Teuchos::as;
00035   vector<T> a2;
00036   TEST_EQUALITY_CONST( as<int>(a2.size()), 0 );
00037   TEST_EQUALITY_CONST( a2.empty(), true );
00038 }
00039 
00040 
00041 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, sizedConstruct, T )
00042 {
00043   using std::vector;
00044   using Teuchos::as;
00045   using Teuchos::getConst;
00046   typedef typename std::vector<T>::size_type size_type;
00047   vector<T> a(n);
00048   TEST_EQUALITY_CONST( a.empty(), false );
00049   TEST_EQUALITY( as<int>(a.size()), n );
00050   TEST_COMPARE( a.max_size(), >=, as<size_type>(n) );
00051   TEST_COMPARE( as<int>(a.capacity()), >=, n );
00052 }
00053 
00054 
00055 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, operatorBracket, T )
00056 {
00057   using std::vector;
00058   using Teuchos::as;
00059   out << "\nTest that a[i] == i ... ";
00060   vector<T> a = generatevector<T>(n);;
00061   bool local_success = true;
00062   for( int i = 0; i < n; ++i ) {
00063     TEST_ARRAY_ELE_EQUALITY( a, i, as<T>(i) );
00064   }
00065   if (local_success) out << "passed\n";
00066   else success = false;
00067 }
00068 
00069 
00070 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, constAt, T )
00071 {
00072   using std::vector;
00073   using Teuchos::as;
00074   out << "\nTest that a.at(i) == i ...\n";
00075   vector<T> a = generatevector<T>(n);;
00076   bool local_success = true;
00077   for( int i = 0; i < n; ++i ) {
00078     TEUCHOS_TEST_EQUALITY( a.at(i), as<T>(i), out, local_success );
00079   }
00080   if (local_success) out << "passed\n";
00081   else success = false;
00082 }
00083 
00084 
00085 //
00086 // Instantiations
00087 //
00088 
00089 
00090 #define UNIT_TEST_GROUP( T ) \
00091   TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, defaultConstruct, T ) \
00092   TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, sizedConstruct, T ) \
00093   TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, operatorBracket, T ) \
00094   TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( vector, constAt, T )
00095 
00096 
00097 UNIT_TEST_GROUP(int)
00098 UNIT_TEST_GROUP(float)
00099 UNIT_TEST_GROUP(double)
00100 
00101 
00102 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:14:01 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1