34 using Teuchos::outArg;
40 typedef typename Array<T>::size_type size_type;
46 <<
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" of size = "<<n
52 out <<
"\nA) Initial setup ...\n\n";
70 out <<
"\nInitializing data ...\n";
71 for(
int i = 0; i <
n; ++i )
76 out <<
"\nTest that a[i] == i ... ";
77 bool local_success =
true;
78 for(
int i = 0; i <
n; ++i ) {
81 if (local_success) out <<
"passed\n";
86 out <<
"\nTest that a.at(i) == i ...\n";
87 bool local_success =
true;
88 for(
int i = 0; i <
n; ++i ) {
91 if (local_success) out <<
"passed\n";
96 out <<
"\nB) Test constructors, assignment operators etc ...\n";
100 out <<
"\nTest default constructor ...\n";
111 out <<
"\nTest copy conversion to and from Teuchos::Array and std::vector ...\n";
118 out <<
"\nTest assignment operator taking an std::vector ...\n";
126 out <<
"\nTest construction using iterators ...\n";
128 Array<T> a2(a.begin(),a.end());
133 out <<
"\nTest copy construction ...\n";
139 out <<
"\nTest array assignment operator ...\n";
146 out <<
"\nTest array assign(...) ...\n";
148 a2.assign(a.begin(),a.end());
153 out <<
"\nTest iterator access and then resize ...\n";
155 const Array<T> &ca2 = a2;
156 Array<T> a3(ca2.begin(),ca2.end());
162 out <<
"\nC) Test element access ...\n";
167 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
172 #else //HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
175 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
178 out <<
"\nD) Test iterator access ...\n";
181 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
184 out <<
"\nTesting functions that should throw for empty container ...\n";
194 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
197 out <<
"\nTest that a2.begin() == a2.end() for empty a2 ...\n";
203 out <<
"\nTest nonconst forward iterator access ... ";
204 bool local_success =
true;
205 typedef typename Array<T>::iterator iter_t;
206 iter_t iter = a.begin();
207 for (
int i = 0; i <
n; ++i, ++iter )
209 iter = NullIteratorTraits<iter_t>::getNull();
210 if (local_success) out <<
"passed\n";
211 else success =
false;
215 out <<
"\nTest const forward iterator access ... ";
216 bool local_success =
true;
217 typedef typename Array<T>::const_iterator iter_t;
219 for (
int i = 0; i <
n; ++i, ++iter )
221 iter = NullIteratorTraits<iter_t>::getNull();
222 if (local_success) out <<
"passed\n";
223 else success =
false;
226 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
229 out <<
"\nTest forward iterators dereferenced out of bounds ...\n";
236 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
239 out <<
"\nTest that a2.rbegin() == a2.rend() for empty a2 ...\n";
245 out <<
"\nTest nonconst reverse iterator access ... ";
246 bool local_success =
true;
247 typedef typename Array<T>::reverse_iterator iter_t;
248 iter_t iter = a.rbegin();
249 for (
int i = n-1; i >= 0; --i, ++iter )
251 iter = NullIteratorTraits<iter_t>::getNull();
252 if (local_success) out <<
"passed\n";
253 else success =
false;
257 out <<
"\nTest const reverse iterator access ... ";
258 bool local_success =
true;
259 typedef typename Array<T>::const_reverse_iterator iter_t;
261 for (
int i = n-1; i >= 0; --i, ++iter )
263 iter = NullIteratorTraits<iter_t>::getNull();
264 if (local_success) out <<
"passed\n";
265 else success =
false;
268 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
270 out <<
"\nTest reverse iterators dereferenced out of bounds ...\n";
276 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
279 out <<
"\nTest that an iterator reference set to null does not throw ...\n";
280 typedef typename Array<T>::iterator iter_t;
281 iter_t iter = NullIteratorTraits<iter_t>::getNull();
283 iter = NullIteratorTraits<iter_t>::getNull() );
287 out <<
"\nTest that a dangling iterator reference throws exception ...\n";
288 typedef typename Array<T>::iterator iter_t;
289 iter_t iter = NullIteratorTraits<iter_t>::getNull();
294 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
296 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
301 out <<
"\nE) Test insertion and deletion functions ...\n";
305 out <<
"\nTest push_back(x) ...\n";
307 for (
int i = 0; i <
n; ++i ) {
308 a2.push_back(as<T>(i));
318 out <<
"\nTest pop_back() ...\n";
320 for (
int i = n-1; i >= 0; --i ) {
327 out <<
"\nTest insert(iter,x) ...\n";
329 for (
int i = 0; i <
n; ++i ) {
330 const typename Array<T>::iterator
331 iter = a2.insert(a2.end(), as<T>(i));
338 out <<
"\nTest insert(iter,1,x) ...\n";
340 for (
int i = 0; i <
n; ++i )
341 a2.insert(a2.end(),1,i);
346 out <<
"\nTest insert(iter,first,last) ...\n";
348 for (
int i = 0; i <
n; ++i )
349 a2.insert(a2.end(),a.begin()+i,a.begin()+i+1);
354 out <<
"\nTest append(x) ...\n";
356 for (
int i = 0; i <
n; ++i )
362 out <<
"\nTest erase(iter) ...\n";
364 for (
int i = 0; i <
n; ++i ) {
367 a2.erase(a2.begin());
372 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
375 out <<
"\nTest trying to erase twice with the same iterator which should throw ...\n";
377 const typename Array<T>::iterator iter = a2.begin();
383 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
397 out <<
"\nTest remove(i) ...\n";
399 for (
int i = 0; i <
n; ++i ) {
408 out <<
"\nTest erase(begin(),end()) ...\n";
410 a2.erase(a2.begin(),a2.end());
415 out <<
"\nTest member swap() ...\n";
418 for (
int i = 0; i <
n; ++i )
425 out <<
"\nTest non-member swap() ...\n";
428 for (
int i = 0; i <
n; ++i )
435 out <<
"\nTest clear() ...\n";
442 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
461 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
464 out <<
"\nTest hasArrayBoundsChecking() ... \n";
465 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
473 out <<
"\nG) Test views ...\n";
477 out <<
"\nTest full non-const subview ...\n";
478 const ArrayView<T> av2 = a(0,n);
483 out <<
"\nTest full shorthand non-const subview ...\n";
484 const ArrayView<T> av2 = a();
489 out <<
"\nTest full const subview ...\n";
490 const ArrayView<const T> cav2 =
getConst(a)(0,
n);
495 out <<
"\nTest full non-const to const subview ...\n";
496 const ArrayView<const T> cav2 = a(0, n);
501 out <<
"\nTest full short-hand const subview ...\n";
502 const ArrayView<const T> cav2 =
getConst(a)();
507 out <<
"\nTest non-const initial range view ...\n";
508 Array<T> a2(n,as<T>(-1));
509 const ArrayView<T> av2 = a2;
510 const ArrayView<T> av2_end = av2(0,n-1);
512 av2_end.assign( a(0,n-1) );
513 av2.back() = as<T>(n-1);
518 out <<
"\nTest non-const middle range view ...\n";
519 Array<T> a2(n,as<T>(-1));
520 const ArrayView<T> av2 = a2;
521 const ArrayView<T> av2_middle = av2(1,n-2);
523 av2_middle.assign( a(1,n-2) );
524 av2.front() = as<T>(0);
525 av2.back() = as<T>(n-1);
530 out <<
"\nTest const view ... ";
531 const ArrayView<const T> av2 = a;
532 const ArrayView<const T> av2_middle = av2(1,n-2);
534 bool local_success =
true;
535 for (
int i = 0; i < n-2; ++i )
537 if (local_success) out <<
"passed\n";
538 else success =
false;
542 out <<
"\nTest constructing Array<T> from ArrayView<T> ...\n";
543 const ArrayView<T> av2 = a;
549 out <<
"\nTest constructing Array<T> from ArrayView<const T> ...\n";
550 const ArrayView<const T> av2 = a;
556 out <<
"\nTest comparison operators ...\n";
567 out <<
"\nH) Test tuple(...) construction ...\n";
571 const size_type m = 1;
572 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
573 Array<T> am = tuple<T>(0);
575 out <<
"Test that am[i] == i ... ";
576 bool local_success =
true;
577 for( size_type i = 0; i < m; ++i ) {
580 if (local_success) out <<
"passed\n";
581 else success =
false;
585 const size_type m = 2;
586 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
587 Array<T> am = tuple<T>(0,1);
589 out <<
"Test that am[i] == i ... ";
590 bool local_success =
true;
591 for( size_type i = 0; i < m; ++i ) {
594 if (local_success) out <<
"passed\n";
595 else success =
false;
599 const size_type m = 3;
600 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
601 Array<T> am = tuple<T>(0,1,2);
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 = 4;
614 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
615 Array<T> am = tuple<T>(0,1,2,3);
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 = 5;
628 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
629 Array<T> am = tuple<T>(0,1,2,3,4);
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 = 6;
642 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
643 Array<T> am = tuple<T>(0,1,2,3,4,5);
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 = 7;
656 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
657 Array<T> am = tuple<T>(0,1,2,3,4,5,6);
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 = 8;
670 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
671 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7);
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 = 9;
684 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
685 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8);
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 = 10;
698 out <<
"\nTest Array<T> = tuple(0,...,"<<m-1<<
")\n";
699 Array<T> am = tuple<T>(0,1,2,3,4,5,6,7,8,9);
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 out <<
"\nTest taking an empty view ...\n";
712 const ArrayView<T> av = a(0,0);
716 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
718 out <<
"\nTest taking views outside of valid range ...\n";
723 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
739 typedef typename Array<T>::size_type size_type;
745 <<
"\n*** Testing Array<"<<T_name<<
"> for opaque type without TNT of size = "<<n
751 out <<
"\nA) Initial setup ...\n\n";
769 out <<
"\nInitializing data ...\n";
770 for(
int i = 0; i <
n; ++i )
775 out <<
"\nTest that a[i] == "<<someValue<<
" ... ";
776 bool local_success =
true;
777 for(
int i = 0; i <
n; ++i ) {
780 if (local_success) out <<
"passed\n";
781 else success =
false;
784 #ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
786 out <<
"\nTest taking a view of the array ...\n";
787 const ArrayView<T> av = a();
792 #endif // not HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
809 typedef typename Array<T>::size_type size_type;
815 <<
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" for opaque type with TNT of size = "<<n
821 out <<
"\nA) Initial setup ...\n\n";
839 out <<
"\nInitializing data ...\n";
840 for(
int i = 0; i <
n; ++i )
845 out <<
"\nTest that a[i] == "<<someValue<<
" ... ";
846 bool local_success =
true;
847 for(
int i = 0; i <
n; ++i ) {
850 if (local_success) out <<
"passed\n";
851 else success =
false;
855 out <<
"\nTest taking a view of the array ...\n";
856 const ArrayView<T> av = a();
860 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
862 out <<
"\nTest taking views outside of valid range ...\n";
867 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
884 int main(
int argc,
char* argv[] ) {
904 CommandLineProcessor clp(
false);
907 clp.setOption(
"n", &n,
"Number of elements in the array" );
909 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
911 if ( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
912 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
918 result = testArray<int>(
n,*out);
919 if (!result) success =
false;
921 result = testArray<float>(
n,*out);
922 if (!result) success =
false;
924 result = testArray<double>(
n,*out);
925 if (!result) success =
false;
931 result = testArrayOpaqueWithoutTNT<Opaque_handle>(
"Opaque_handle",
n,
933 if (!result) success =
false;
936 if (!result) success =
false;
939 if (!result) success =
false;
947 *out <<
"\nEnd Result: TEST PASSED" << std::endl;
949 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
951 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...