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";
144 std::vector<T> v2 = createVector(a);
150 out <<
"\nTest assignment operator taking an std::vector ...\n";
151 std::vector<T> v2 = createVector(a);
158 out <<
"\nTest construction using iterators ...\n";
159 std::vector<T> v2 = createVector(a);
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
210 out <<
"\nD) Test iterator access ...\n";
213#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
216 out <<
"\nTesting functions that should throw for empty container ...\n";
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;
250 iter_t iter = getConst(a).begin();
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";
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;
292 iter_t iter = getConst(a).rbegin();
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";
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
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();
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
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";