66   using Teuchos::outArg;
 
   72   typedef typename Array<T>::size_type size_type;
 
   78     << 
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" of size = "<<n
 
   84   out << 
"\nA) Initial setup ...\n\n";
 
  102     out << 
"\nInitializing data ...\n";
 
  103     for( 
int i = 0; i < 
n; ++i )
 
  108     out << 
"\nTest that a[i] == i ... ";
 
  109     bool local_success = 
true;
 
  110     for( 
int i = 0; i < 
n; ++i ) {
 
  113     if (local_success) out << 
"passed\n";
 
  114     else success = 
false;
 
  118     out << 
"\nTest that a.at(i) == i ...\n";
 
  119     bool local_success = 
true;
 
  120     for( 
int i = 0; i < 
n; ++i ) {
 
  123     if (local_success) out << 
"passed\n";
 
  124     else success = 
false;
 
  128   out << 
"\nB) Test constructors, assignment operators etc ...\n";
 
  132     out << 
"\nTest default constructor ...\n";
 
  143     out << 
"\nTest copy conversion to and from Teuchos::Array and std::vector ...\n";
 
  150     out << 
"\nTest assignment operator taking an std::vector ...\n";
 
  158     out << 
"\nTest construction using iterators ...\n";
 
  160     Array<T> a2(a.begin(),a.end());
 
  165     out << 
"\nTest copy construction ...\n";
 
  171     out << 
"\nTest array assignment operator ...\n";
 
  178     out << 
"\nTest array assign(...) ...\n";
 
  180     a2.assign(a.begin(),a.end());
 
  185     out << 
"\nTest iterator access and then resize ...\n";
 
  187     const Array<T> &ca2 = a2;
 
  188     Array<T> a3(ca2.begin(),ca2.end());
 
  194   out << 
"\nC) Test element access ...\n";
 
  199 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  204 #else //HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  207 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  210   out << 
"\nD) Test iterator access ...\n";
 
  213 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  216     out << 
"\nTesting functions that should throw for empty container ...\n";
 
  226 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  229     out << 
"\nTest that a2.begin() == a2.end() for empty a2 ...\n";
 
  235     out << 
"\nTest nonconst forward iterator access ... ";
 
  236     bool local_success = 
true;
 
  237     typedef typename Array<T>::iterator iter_t;
 
  238     iter_t iter = a.begin();
 
  239     for ( 
int i = 0; i < 
n; ++i, ++iter )
 
  241     iter = NullIteratorTraits<iter_t>::getNull();
 
  242     if (local_success) out << 
"passed\n";
 
  243     else success = 
false;
 
  247     out << 
"\nTest const forward iterator access ... ";
 
  248     bool local_success = 
true;
 
  249     typedef typename Array<T>::const_iterator iter_t;
 
  251     for ( 
int i = 0; i < 
n; ++i, ++iter )
 
  253     iter = NullIteratorTraits<iter_t>::getNull();
 
  254     if (local_success) out << 
"passed\n";
 
  255     else success = 
false;
 
  258 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  261     out << 
"\nTest forward iterators dereferenced out of bounds ...\n";
 
  268 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  271     out << 
"\nTest that a2.rbegin() == a2.rend() for empty a2 ...\n";
 
  277     out << 
"\nTest nonconst reverse iterator access ... ";
 
  278     bool local_success = 
true;
 
  279     typedef typename Array<T>::reverse_iterator iter_t;
 
  280     iter_t iter = a.rbegin();
 
  281     for ( 
int i = n-1; i >= 0; --i, ++iter )
 
  283     iter = NullIteratorTraits<iter_t>::getNull();
 
  284     if (local_success) out << 
"passed\n";
 
  285     else success = 
false;
 
  289     out << 
"\nTest const reverse iterator access ... ";
 
  290     bool local_success = 
true;
 
  291     typedef typename Array<T>::const_reverse_iterator iter_t;
 
  293     for ( 
int i = n-1; i >= 0; --i, ++iter )
 
  295     iter = NullIteratorTraits<iter_t>::getNull();
 
  296     if (local_success) out << 
"passed\n";
 
  297     else success = 
false;
 
  300 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  302     out << 
"\nTest reverse iterators dereferenced out of bounds ...\n";
 
  308 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  311     out << 
"\nTest that an iterator reference set to null does not throw ...\n";
 
  312     typedef typename Array<T>::iterator iter_t;
 
  313     iter_t iter = NullIteratorTraits<iter_t>::getNull();
 
  315       iter = NullIteratorTraits<iter_t>::getNull() );
 
  319     out << 
"\nTest that a dangling iterator reference throws exception ...\n";
 
  320     typedef typename Array<T>::iterator iter_t;
 
  321     iter_t iter = NullIteratorTraits<iter_t>::getNull();
 
  326 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  328 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  333   out << 
"\nE) Test insertion and deletion functions ...\n";
 
  337     out << 
"\nTest push_back(x) ...\n";
 
  339     for ( 
int i = 0; i < 
n; ++i ) {
 
  340       a2.push_back(as<T>(i));
 
  350     out << 
"\nTest pop_back() ...\n";
 
  352     for ( 
int i = n-1; i >= 0; --i ) {
 
  359     out << 
"\nTest insert(iter,x) ...\n";
 
  361     for ( 
int i = 0; i < 
n; ++i ) {
 
  362       const typename Array<T>::iterator
 
  363         iter = a2.insert(a2.end(), as<T>(i));
 
  370     out << 
"\nTest insert(iter,1,x) ...\n";
 
  372     for ( 
int i = 0; i < 
n; ++i )
 
  373       a2.insert(a2.end(),1,i);
 
  378     out << 
"\nTest insert(iter,first,last) ...\n";
 
  380     for ( 
int i = 0; i < 
n; ++i )
 
  381       a2.insert(a2.end(),a.begin()+i,a.begin()+i+1);
 
  386     out << 
"\nTest append(x) ...\n";
 
  388     for ( 
int i = 0; i < 
n; ++i )
 
  394     out << 
"\nTest erase(iter) ...\n";
 
  396     for ( 
int i = 0; i < 
n; ++i ) {
 
  399       a2.erase(a2.begin());
 
  404 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  407     out << 
"\nTest trying to erase twice with the same iterator which should throw ...\n";
 
  409     const typename Array<T>::iterator iter = a2.begin();
 
  415 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  429     out << 
"\nTest remove(i) ...\n";
 
  431     for ( 
int i = 0; i < 
n; ++i ) {
 
  440     out << 
"\nTest erase(begin(),end()) ...\n";
 
  442     a2.erase(a2.begin(),a2.end());
 
  447     out << 
"\nTest member swap() ...\n";
 
  450     for ( 
int i = 0; i < 
n; ++i )
 
  457     out << 
"\nTest non-member swap() ...\n";
 
  460     for ( 
int i = 0; i < 
n; ++i )
 
  467     out << 
"\nTest clear() ...\n";
 
  474 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  493 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  496     out << 
"\nTest hasArrayBoundsChecking() ... \n";
 
  497 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  505   out << 
"\nG) Test views ...\n";
 
  509     out << 
"\nTest full non-const subview ...\n";
 
  510     const ArrayView<T> av2 = a(0,n);
 
  515     out << 
"\nTest full shorthand non-const subview ...\n";
 
  516     const ArrayView<T> av2 = a();
 
  521     out << 
"\nTest full const subview ...\n";
 
  522     const ArrayView<const T> cav2 = 
getConst(a)(0, 
n);
 
  527     out << 
"\nTest full non-const to const subview ...\n";
 
  528     const ArrayView<const T> cav2 = a(0, n);
 
  533     out << 
"\nTest full short-hand const subview ...\n";
 
  534     const ArrayView<const T> cav2 = 
getConst(a)();
 
  539     out << 
"\nTest non-const initial range view ...\n";
 
  540     Array<T> a2(n,as<T>(-1));
 
  541     const ArrayView<T> av2 = a2; 
 
  542     const ArrayView<T> av2_end = av2(0,n-1);
 
  544     av2_end.assign( a(0,n-1) );
 
  545     av2.back() = as<T>(n-1);
 
  550     out << 
"\nTest non-const middle range view ...\n";
 
  551     Array<T> a2(n,as<T>(-1));
 
  552     const ArrayView<T> av2 = a2; 
 
  553     const ArrayView<T> av2_middle = av2(1,n-2);
 
  555     av2_middle.assign( a(1,n-2) );
 
  556     av2.front() = as<T>(0);
 
  557     av2.back() = as<T>(n-1);
 
  562     out << 
"\nTest const view ... ";
 
  563     const ArrayView<const T> av2 = a; 
 
  564     const ArrayView<const T> av2_middle = av2(1,n-2);
 
  566     bool local_success = 
true;
 
  567     for ( 
int i = 0; i < n-2; ++i )
 
  569     if (local_success) out << 
"passed\n";
 
  570     else success = 
false;
 
  574     out << 
"\nTest constructing Array<T> from ArrayView<T> ...\n";
 
  575     const ArrayView<T> av2 = a;
 
  581     out << 
"\nTest constructing Array<T> from ArrayView<const T> ...\n";
 
  582     const ArrayView<const T> av2 = a;
 
  588     out << 
"\nTest comparison operators ...\n";
 
  599   out << 
"\nH) Test tuple(...) construction ...\n";
 
  603     const size_type m = 1;
 
  604     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  605     Array<T> am = tuple<T>(0);
 
  607     out << 
"Test that am[i] == i ... ";
 
  608     bool local_success = 
true;
 
  609     for( size_type i = 0; i < m; ++i ) {
 
  612     if (local_success) out << 
"passed\n";
 
  613     else success = 
false;
 
  617     const size_type m = 2;
 
  618     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  619     Array<T> am = tuple<T>(0,1);
 
  621     out << 
"Test that am[i] == i ... ";
 
  622     bool local_success = 
true;
 
  623     for( size_type i = 0; i < m; ++i ) {
 
  626     if (local_success) out << 
"passed\n";
 
  627     else success = 
false;
 
  631     const size_type m = 3;
 
  632     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  633     Array<T> am = tuple<T>(0,1,2);
 
  635     out << 
"Test that am[i] == i ... ";
 
  636     bool local_success = 
true;
 
  637     for( size_type i = 0; i < m; ++i ) {
 
  640     if (local_success) out << 
"passed\n";
 
  641     else success = 
false;
 
  645     const size_type m = 4;
 
  646     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  647     Array<T> am = tuple<T>(0,1,2,3);
 
  649     out << 
"Test that am[i] == i ... ";
 
  650     bool local_success = 
true;
 
  651     for( size_type i = 0; i < m; ++i ) {
 
  654     if (local_success) out << 
"passed\n";
 
  655     else success = 
false;
 
  659     const size_type m = 5;
 
  660     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  661     Array<T> am = tuple<T>(0,1,2,3,4);
 
  663     out << 
"Test that am[i] == i ... ";
 
  664     bool local_success = 
true;
 
  665     for( size_type i = 0; i < m; ++i ) {
 
  668     if (local_success) out << 
"passed\n";
 
  669     else success = 
false;
 
  673     const size_type m = 6;
 
  674     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  675     Array<T> am = tuple<T>(0,1,2,3,4,5);
 
  677     out << 
"Test that am[i] == i ... ";
 
  678     bool local_success = 
true;
 
  679     for( size_type i = 0; i < m; ++i ) {
 
  682     if (local_success) out << 
"passed\n";
 
  683     else success = 
false;
 
  687     const size_type m = 7;
 
  688     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  689     Array<T> am = tuple<T>(0,1,2,3,4,5,6);
 
  691     out << 
"Test that am[i] == i ... ";
 
  692     bool local_success = 
true;
 
  693     for( size_type i = 0; i < m; ++i ) {
 
  696     if (local_success) out << 
"passed\n";
 
  697     else success = 
false;
 
  701     const size_type m = 8;
 
  702     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  703     Array<T> am = tuple<T>(0,1,2,3,4,5,6,7);
 
  705     out << 
"Test that am[i] == i ... ";
 
  706     bool local_success = 
true;
 
  707     for( size_type i = 0; i < m; ++i ) {
 
  710     if (local_success) out << 
"passed\n";
 
  711     else success = 
false;
 
  715     const size_type m = 9;
 
  716     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  717     Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8);
 
  719     out << 
"Test that am[i] == i ... ";
 
  720     bool local_success = 
true;
 
  721     for( size_type i = 0; i < m; ++i ) {
 
  724     if (local_success) out << 
"passed\n";
 
  725     else success = 
false;
 
  729     const size_type m = 10;
 
  730     out << 
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
 
  731     Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8,9);
 
  733     out << 
"Test that am[i] == i ... ";
 
  734     bool local_success = 
true;
 
  735     for( size_type i = 0; i < m; ++i ) {
 
  738     if (local_success) out << 
"passed\n";
 
  739     else success = 
false;
 
  743     out << 
"\nTest taking an empty view ...\n";
 
  744     const ArrayView<T> av = a(0,0);
 
  748 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  750     out << 
"\nTest taking views outside of valid range ...\n";
 
  755 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  771   typedef typename Array<T>::size_type size_type;
 
  777     << 
"\n*** Testing Array<"<<T_name<<
"> for opaque type without TNT of size = "<<n
 
  783   out << 
"\nA) Initial setup ...\n\n";
 
  801     out << 
"\nInitializing data ...\n";
 
  802     for( 
int i = 0; i < 
n; ++i )
 
  807     out << 
"\nTest that a[i] == "<<someValue<<
" ... ";
 
  808     bool local_success = 
true;
 
  809     for( 
int i = 0; i < 
n; ++i ) {
 
  812     if (local_success) out << 
"passed\n";
 
  813     else success = 
false;
 
  816 #ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  818     out << 
"\nTest taking a view of the array ...\n";
 
  819     const ArrayView<T> av = a();
 
  824 #endif // not HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  841   typedef typename Array<T>::size_type size_type;
 
  847     << 
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" for opaque type with TNT of size = "<<n
 
  853   out << 
"\nA) Initial setup ...\n\n";
 
  871     out << 
"\nInitializing data ...\n";
 
  872     for( 
int i = 0; i < 
n; ++i )
 
  877     out << 
"\nTest that a[i] == "<<someValue<<
" ... ";
 
  878     bool local_success = 
true;
 
  879     for( 
int i = 0; i < 
n; ++i ) {
 
  882     if (local_success) out << 
"passed\n";
 
  883     else success = 
false;
 
  887     out << 
"\nTest taking a view of the array ...\n";
 
  888     const ArrayView<T> av = a();
 
  892 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  894     out << 
"\nTest taking views outside of valid range ...\n";
 
  899 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 
  916 int main( 
int argc, 
char* argv[] ) {
 
  936     CommandLineProcessor clp(
false); 
 
  939     clp.setOption( 
"n", &n, 
"Number of elements in the array" );
 
  941                 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
 
  943                 if ( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
 
  944                         *out << 
"\nEnd Result: TEST FAILED" << std::endl;
 
  950     result = testArray<int>(
n,*out);
 
  951     if (!result) success = 
false;
 
  953     result = testArray<float>(
n,*out);
 
  954     if (!result) success = 
false;
 
  956     result = testArray<double>(
n,*out);
 
  957     if (!result) success = 
false;
 
  963     result = testArrayOpaqueWithoutTNT<Opaque_handle>(
"Opaque_handle", 
n,
 
  965     if (!result) success = 
false;
 
  968     if (!result) success = 
false;
 
  971     if (!result) success = 
false;
 
  979     *out << 
"\nEnd Result: TEST PASSED" << std::endl;
 
  981     *out << 
"\nEnd Result: TEST FAILED" << std::endl;
 
  983   return ( success ? 0 : 1 );
 
Dangling reference error exception class. 
 
Null reference error exception class. 
 
const Opaque_handle OPAQUE_HANDLE_NULL
 
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions. 
 
#define TEST_ITER_EQUALITY(iter1, iter2)
Assert that two iterators are equal. 
 
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
 
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2. 
 
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
 
#define TEST_COMPARE(v1, comp, v2)
Assert that v1 comp v2 (where comp = '==', '>=", "!=", etc). 
 
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference. 
 
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
 
Initialize, finalize, and query the global MPI session. 
 
const Opaque2_handle OPAQUE2_HANDLE_NULL
 
Utilities to make writing tests easier. 
 
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
 
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions. 
 
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object. 
 
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2. 
 
const Opaque3_handle OPAQUE3_HANDLE_NULL
 
bool testArrayOpaqueWithTNT(const int n, const T &someValue, Teuchos::FancyOStream &out)
 
bool testArray(const int n, Teuchos::FancyOStream &out)
 
std::string Teuchos_Version()
 
Incompatiable iterators error exception class. 
 
Base traits class for getting a properly initialized null pointer. 
 
TypeTo as(const TypeFrom &t)
Convert from one value type to another. 
 
int main(int argc, char *argv[])
 
Templated array class derived from the STL std::vector. 
 
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0.... 
 
bool testArrayOpaqueWithoutTNT(const std::string &T_name, const int n, const T &someValue, Teuchos::FancyOStream &out)
 
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Test that two values are equal. 
 
Default traits class that just returns typeid(T).name(). 
 
std::vector< T > createVector(const Array< T > &a)
Copy conversion to an std::vector. 
 
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
 
#define TEST_ARRAY_ELE_EQUALITY(a, i, val)
Assert that a[i] == val. 
 
Basic command line parser for input from (argc,argv[]) 
 
Smart reference counting pointer class for automatic garbage collection. 
 
Range error exception class. 
 
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
 
void swap(Teuchos::any &a, Teuchos::any &b)
Special swap for other code to find via Argument Dependent Lookup. 
 
Definition of Teuchos::as, for conversions between types. 
 
Class that helps parse command line input arguments from (argc,argv[]) and set options. 
 
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...