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);
165 out <<
"\nTest copy construction ...\n";
171 out <<
"\nTest array assignment operator ...\n";
178 out <<
"\nTest array assign(...) ...\n";
185 out <<
"\nTest iterator access and then resize ...\n";
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;
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;
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;
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;
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";
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";
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 ) {
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 ) {
370 out <<
"\nTest insert(iter,1,x) ...\n";
372 for (
int i = 0; i < n; ++i )
378 out <<
"\nTest insert(iter,first,last) ...\n";
380 for (
int i = 0; i < n; ++i )
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 ) {
404#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
407 out <<
"\nTest trying to erase twice with the same iterator which should throw ...\n";
429 out <<
"\nTest remove(i) ...\n";
431 for (
int i = 0; i < n; ++i ) {
440 out <<
"\nTest erase(begin(),end()) ...\n";
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";
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";
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";
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";
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";
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";
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";
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";
777 <<
"\n*** Testing Array<"<<T_name<<
"> for opaque type without TNT of size = "<<n
783 out <<
"\nA) Initial setup ...\n\n";
796 TEST_EQUALITY( getConst(a).getRawPtr(), getConst(a).data() );
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();
847 <<
"\n*** Testing "<<TypeNameTraits<Array<T> >::name()<<
" for opaque type with TNT of size = "<<n
853 out <<
"\nA) Initial setup ...\n\n";
866 TEST_EQUALITY( getConst(a).getRawPtr(), getConst(a).data() );
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";
916int main(
int argc,
char* argv[] ) {
939 clp.
setOption(
"n", &n,
"Number of elements in the array" );
944 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
951 if (!result) success =
false;
954 if (!result) success =
false;
957 if (!result) success =
false;
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 );
bool testArrayOpaqueWithoutTNT(const std::string &T_name, const int n, const T &someValue, Teuchos::FancyOStream &out)
bool testArray(const int n, Teuchos::FancyOStream &out)
bool testArrayOpaqueWithTNT(const int n, const T &someValue, Teuchos::FancyOStream &out)
const Opaque_handle OPAQUE_HANDLE_NULL
const Opaque3_handle OPAQUE3_HANDLE_NULL
const Opaque2_handle OPAQUE2_HANDLE_NULL
Templated array class derived from the STL std::vector.
Basic command line parser for input from (argc,argv[]).
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Utilities to make writing tests easier.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
#define TEST_ARRAY_ELE_EQUALITY(a, i, val)
Assert that a[i] == val.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails).
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
#define TEST_COMPARE(v1, comp, v2)
Assert that v1 comp v2 (where comp = '==', '>=", "!=", etc).
#define TEST_ITER_EQUALITY(iter1, iter2)
Assert that two iterators are equal.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Test that two values are equal.
Definition of Teuchos::as, for conversions between types.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
iterator insert(iterator position, const value_type &x)
friend void swap(Array< T2 > &a1, Array< T2 > &a2)
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
int length() const
Return number of elements in the array.
std::vector< T >::iterator iterator
The type of a forward iterator.
Ordinal size_type
The type of Array sizes and capacities.
std::vector< T >::reverse_iterator reverse_iterator
The type of a reverse iterator.
void assign(size_type n, const value_type &val)
reference at(size_type i)
size_type capacity() const
void remove(int i)
Remove the i-th element from the array, with optional boundschecking.
void push_back(const value_type &x)
std::vector< T >::const_reverse_iterator const_reverse_iterator
The type of a const reverse iterator.
static bool hasBoundsChecking()
Return true if Array has been compiled with boundschecking on.
reverse_iterator rbegin()
size_type max_size() const
T * data()
Return a raw pointer to beginning of array.
void resize(size_type new_size, const value_type &x=value_type())
std::vector< T >::const_iterator const_iterator
The type of a const forward iterator.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
iterator erase(iterator position)
Class that helps parse command line input arguments from (argc,argv[]) and set options.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
Dangling reference error exception class.
Initialize, finalize, and query the global MPI session.
Incompatiable iterators error exception class.
Base traits class for getting a properly initialized null pointer.
Null reference error exception class.
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
Smart reference counting pointer class for automatic garbage collection.
Range error exception class.
Tuple< T, 1 > tuple(const T &a)
Create a Tuple<T,1>.
Default traits class that just returns typeid(T).name().
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
std::string Teuchos_Version()