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";
100 out <<
"\nInitializing data ...\n";
101 for(
int i = 0; i <
n; ++i )
106 out <<
"\nTest that a[i] == i ... ";
107 bool local_success =
true;
108 for(
int i = 0; i <
n; ++i ) {
111 if (local_success) out <<
"passed\n";
112 else success =
false;
116 out <<
"\nTest that a.at(i) == i ...\n";
117 bool local_success =
true;
118 for(
int i = 0; i <
n; ++i ) {
121 if (local_success) out <<
"passed\n";
122 else success =
false;
126 out <<
"\nB) Test constructors, assignment operators etc ...\n";
130 out <<
"\nTest default constructor ...\n";
139 out <<
"\nTest copy conversion to and from Teuchos::Array and std::vector ...\n";
146 out <<
"\nTest assignment operator taking an std::vector ...\n";
154 out <<
"\nTest construction using iterators ...\n";
156 Array<T> a2(a.begin(),a.end());
161 out <<
"\nTest copy construction ...\n";
167 out <<
"\nTest array assignment operator ...\n";
174 out <<
"\nTest array assign(...) ...\n";
176 a2.assign(a.begin(),a.end());
181 out <<
"\nTest iterator access and then resize ...\n";
183 const Array<T> &ca2 = a2;
184 Array<T> a3(ca2.begin(),ca2.end());
190 out <<
"\nC) Test element access ...\n";
195 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 200 #else //HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 203 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 206 out <<
"\nD) Test iterator access ...\n";
209 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 212 out <<
"\nTesting functions that should throw for empty container ...\n";
222 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 225 out <<
"\nTest that a2.begin() == a2.end() for empty a2 ...\n";
231 out <<
"\nTest nonconst forward iterator access ... ";
232 bool local_success =
true;
233 typedef typename Array<T>::iterator iter_t;
234 iter_t iter = a.begin();
235 for (
int i = 0; i <
n; ++i, ++iter )
237 iter = NullIteratorTraits<iter_t>::getNull();
238 if (local_success) out <<
"passed\n";
239 else success =
false;
243 out <<
"\nTest const forward iterator access ... ";
244 bool local_success =
true;
245 typedef typename Array<T>::const_iterator iter_t;
247 for (
int i = 0; i <
n; ++i, ++iter )
249 iter = NullIteratorTraits<iter_t>::getNull();
250 if (local_success) out <<
"passed\n";
251 else success =
false;
254 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 257 out <<
"\nTest forward iterators dereferenced out of bounds ...\n";
264 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 267 out <<
"\nTest that a2.rbegin() == a2.rend() for empty a2 ...\n";
273 out <<
"\nTest nonconst reverse iterator access ... ";
274 bool local_success =
true;
275 typedef typename Array<T>::reverse_iterator iter_t;
276 iter_t iter = a.rbegin();
277 for (
int i =
n-1; i >= 0; --i, ++iter )
279 iter = NullIteratorTraits<iter_t>::getNull();
280 if (local_success) out <<
"passed\n";
281 else success =
false;
285 out <<
"\nTest const reverse iterator access ... ";
286 bool local_success =
true;
287 typedef typename Array<T>::const_reverse_iterator iter_t;
289 for (
int i =
n-1; i >= 0; --i, ++iter )
291 iter = NullIteratorTraits<iter_t>::getNull();
292 if (local_success) out <<
"passed\n";
293 else success =
false;
296 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 298 out <<
"\nTest reverse iterators dereferenced out of bounds ...\n";
304 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 307 out <<
"\nTest that an iterator reference set to null does not throw ...\n";
308 typedef typename Array<T>::iterator iter_t;
309 iter_t iter = NullIteratorTraits<iter_t>::getNull();
311 iter = NullIteratorTraits<iter_t>::getNull() );
315 out <<
"\nTest that a dangling iterator reference throws exception ...\n";
316 typedef typename Array<T>::iterator iter_t;
317 iter_t iter = NullIteratorTraits<iter_t>::getNull();
322 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 324 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 329 out <<
"\nE) Test insertion and deletion functions ...\n";
333 out <<
"\nTest push_back(x) ...\n";
335 for (
int i = 0; i <
n; ++i ) {
336 a2.push_back(as<T>(i));
346 out <<
"\nTest pop_back() ...\n";
348 for (
int i =
n-1; i >= 0; --i ) {
355 out <<
"\nTest insert(iter,x) ...\n";
357 for (
int i = 0; i <
n; ++i ) {
358 const typename Array<T>::iterator
359 iter = a2.insert(a2.end(), as<T>(i));
366 out <<
"\nTest insert(iter,1,x) ...\n";
368 for (
int i = 0; i <
n; ++i )
369 a2.insert(a2.end(),1,i);
374 out <<
"\nTest insert(iter,first,last) ...\n";
376 for (
int i = 0; i <
n; ++i )
377 a2.insert(a2.end(),a.begin()+i,a.begin()+i+1);
382 out <<
"\nTest append(x) ...\n";
384 for (
int i = 0; i <
n; ++i )
390 out <<
"\nTest erase(iter) ...\n";
392 for (
int i = 0; i <
n; ++i ) {
395 a2.erase(a2.begin());
400 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 403 out <<
"\nTest trying to erase twice with the same iterator which should throw ...\n";
405 const typename Array<T>::iterator iter = a2.begin();
411 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 425 out <<
"\nTest remove(i) ...\n";
427 for (
int i = 0; i <
n; ++i ) {
436 out <<
"\nTest erase(begin(),end()) ...\n";
438 a2.erase(a2.begin(),a2.end());
443 out <<
"\nTest member swap() ...\n";
446 for (
int i = 0; i <
n; ++i )
453 out <<
"\nTest non-member swap() ...\n";
456 for (
int i = 0; i <
n; ++i )
463 out <<
"\nTest clear() ...\n";
470 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 489 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 492 out <<
"\nTest hasArrayBoundsChecking() ... \n";
493 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 501 out <<
"\nG) Test views ...\n";
505 out <<
"\nTest full non-const subview ...\n";
506 const ArrayView<T> av2 = a(0,
n);
511 out <<
"\nTest full shorthand non-const subview ...\n";
512 const ArrayView<T> av2 = a();
517 out <<
"\nTest full const subview ...\n";
518 const ArrayView<const T> cav2 =
getConst(a)(0,
n);
523 out <<
"\nTest full non-const to const subview ...\n";
524 const ArrayView<const T> cav2 = a(0,
n);
529 out <<
"\nTest full short-hand const subview ...\n";
530 const ArrayView<const T> cav2 =
getConst(a)();
535 out <<
"\nTest non-const initial range view ...\n";
536 Array<T> a2(
n,as<T>(-1));
537 const ArrayView<T> av2 = a2;
538 const ArrayView<T> av2_end = av2(0,
n-1);
540 av2_end.assign( a(0,
n-1) );
541 av2.back() = as<T>(
n-1);
546 out <<
"\nTest non-const middle range view ...\n";
547 Array<T> a2(
n,as<T>(-1));
548 const ArrayView<T> av2 = a2;
549 const ArrayView<T> av2_middle = av2(1,
n-2);
551 av2_middle.assign( a(1,
n-2) );
552 av2.front() = as<T>(0);
553 av2.back() = as<T>(
n-1);
558 out <<
"\nTest const view ... ";
559 const ArrayView<const T> av2 = a;
560 const ArrayView<const T> av2_middle = av2(1,
n-2);
562 bool local_success =
true;
563 for (
int i = 0; i <
n-2; ++i )
565 if (local_success) out <<
"passed\n";
566 else success =
false;
570 out <<
"\nTest constructing Array<T> from ArrayView<T> ...\n";
571 const ArrayView<T> av2 = a;
577 out <<
"\nTest constructing Array<T> from ArrayView<const T> ...\n";
578 const ArrayView<const T> av2 = a;
584 out <<
"\nTest comparison operators ...\n";
595 out <<
"\nH) Test tuple(...) construction ...\n";
599 const size_type m = 1;
600 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
601 Array<T> am = tuple<T>(0);
603 out <<
"Test that am[i] == i ... ";
604 bool local_success =
true;
605 for( size_type i = 0; i < m; ++i ) {
608 if (local_success) out <<
"passed\n";
609 else success =
false;
613 const size_type m = 2;
614 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
615 Array<T> am = tuple<T>(0,1);
617 out <<
"Test that am[i] == i ... ";
618 bool local_success =
true;
619 for( size_type i = 0; i < m; ++i ) {
622 if (local_success) out <<
"passed\n";
623 else success =
false;
627 const size_type m = 3;
628 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
629 Array<T> am = tuple<T>(0,1,2);
631 out <<
"Test that am[i] == i ... ";
632 bool local_success =
true;
633 for( size_type i = 0; i < m; ++i ) {
636 if (local_success) out <<
"passed\n";
637 else success =
false;
641 const size_type m = 4;
642 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
643 Array<T> am = tuple<T>(0,1,2,3);
645 out <<
"Test that am[i] == i ... ";
646 bool local_success =
true;
647 for( size_type i = 0; i < m; ++i ) {
650 if (local_success) out <<
"passed\n";
651 else success =
false;
655 const size_type m = 5;
656 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
657 Array<T> am = tuple<T>(0,1,2,3,4);
659 out <<
"Test that am[i] == i ... ";
660 bool local_success =
true;
661 for( size_type i = 0; i < m; ++i ) {
664 if (local_success) out <<
"passed\n";
665 else success =
false;
669 const size_type m = 6;
670 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
671 Array<T> am = tuple<T>(0,1,2,3,4,5);
673 out <<
"Test that am[i] == i ... ";
674 bool local_success =
true;
675 for( size_type i = 0; i < m; ++i ) {
678 if (local_success) out <<
"passed\n";
679 else success =
false;
683 const size_type m = 7;
684 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
685 Array<T> am = tuple<T>(0,1,2,3,4,5,6);
687 out <<
"Test that am[i] == i ... ";
688 bool local_success =
true;
689 for( size_type i = 0; i < m; ++i ) {
692 if (local_success) out <<
"passed\n";
693 else success =
false;
697 const size_type m = 8;
698 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
699 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7);
701 out <<
"Test that am[i] == i ... ";
702 bool local_success =
true;
703 for( size_type i = 0; i < m; ++i ) {
706 if (local_success) out <<
"passed\n";
707 else success =
false;
711 const size_type m = 9;
712 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
713 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8);
715 out <<
"Test that am[i] == i ... ";
716 bool local_success =
true;
717 for( size_type i = 0; i < m; ++i ) {
720 if (local_success) out <<
"passed\n";
721 else success =
false;
725 const size_type m = 10;
726 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
727 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8,9);
729 out <<
"Test that am[i] == i ... ";
730 bool local_success =
true;
731 for( size_type i = 0; i < m; ++i ) {
734 if (local_success) out <<
"passed\n";
735 else success =
false;
739 out <<
"\nTest taking an empty view ...\n";
740 const ArrayView<T> av = a(0,0);
744 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 746 out <<
"\nTest taking views outside of valid range ...\n";
751 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 767 typedef typename Array<T>::size_type size_type;
773 <<
"\n*** Testing Array<"<<T_name<<
"> for opaque type without TNT of size = "<<
n 779 out <<
"\nA) Initial setup ...\n\n";
795 out <<
"\nInitializing data ...\n";
796 for(
int i = 0; i <
n; ++i )
801 out <<
"\nTest that a[i] == "<<someValue<<
" ... ";
802 bool local_success =
true;
803 for(
int i = 0; i <
n; ++i ) {
806 if (local_success) out <<
"passed\n";
807 else success =
false;
810 #ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 812 out <<
"\nTest taking a view of the array ...\n";
813 const ArrayView<T> av = a();
818 #endif // not HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 835 typedef typename Array<T>::size_type size_type;
841 <<
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" for opaque type with TNT of size = "<<
n 847 out <<
"\nA) Initial setup ...\n\n";
863 out <<
"\nInitializing data ...\n";
864 for(
int i = 0; i <
n; ++i )
869 out <<
"\nTest that a[i] == "<<someValue<<
" ... ";
870 bool local_success =
true;
871 for(
int i = 0; i <
n; ++i ) {
874 if (local_success) out <<
"passed\n";
875 else success =
false;
879 out <<
"\nTest taking a view of the array ...\n";
880 const ArrayView<T> av = a();
884 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 886 out <<
"\nTest taking views outside of valid range ...\n";
891 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 908 int main(
int argc,
char* argv[] ) {
928 CommandLineProcessor clp(
false);
931 clp.setOption(
"n", &
n,
"Number of elements in the array" );
933 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
935 if ( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
936 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
942 result = testArray<int>(
n,*out);
943 if (!result) success =
false;
945 result = testArray<float>(
n,*out);
946 if (!result) success =
false;
948 result = testArray<double>(
n,*out);
949 if (!result) success =
false;
955 result = testArrayOpaqueWithoutTNT<Opaque_handle>(
"Opaque_handle",
n,
957 if (!result) success =
false;
960 if (!result) success =
false;
963 if (!result) success =
false;
971 *out <<
"\nEnd Result: TEST PASSED" << std::endl;
973 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
975 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
void swap(Array< T > &a1, Array< T > &a2)
Non-member swap (specializes default std version).
int main(int argc, char *argv[])
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.
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...
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...