61 using Teuchos::arcpFromArray;
65 using Teuchos::fromStringToArray;
79 std::string(
"Array(double)"));
87 std::string arrayString=
"{}";
88 std::istringstream arrayStream(arrayString);
89 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
90 Array<std::string> arrayStreamVal;
91 arrayStream >> arrayStreamVal;
92 Array<std::string> arrayVal_exp;
98 std::string arrayString =
"{ a, b, c, d }";
99 std::istringstream arrayStream(arrayString);
100 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
101 Array<std::string> arrayStreamVal;
102 arrayStream >> arrayStreamVal;
103 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"a",
"b",
"c",
"d" );
109 std::string arrayString =
"{ (a), b, c, (d) }";
110 std::istringstream arrayStream(arrayString);
111 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
112 Array<std::string> arrayStreamVal;
113 arrayStream >> arrayStreamVal;
114 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"(a)",
"b",
"c",
"(d)" );
120 std::string arrayString =
"{ (a ), b, c, (d ) }";
121 std::istringstream arrayStream(arrayString);
122 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
123 Array<std::string> arrayStreamVal;
124 arrayStream >> arrayStreamVal;
125 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"(a )",
"b",
"c",
"(d )" );
142 TEST_THROW(fromStringToArray<std::string>(
"{ a, b, c"),
143 InvalidArrayStringRepresentation);
144 TEST_THROW(fromStringToArray<std::string>(
"a, b, c}"),
145 InvalidArrayStringRepresentation);
146 TEST_THROW(fromStringToArray<std::string>(
"a, b, c"),
147 InvalidArrayStringRepresentation);
155 std::string arrayString=
"{-}";
156 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
157 Array<std::string> arrayVal_exp = tuple<std::string>(
"-");
162 std::string arrayString=
"{-,-}";
163 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
164 Array<std::string> arrayVal_exp = tuple<std::string>(
"-",
"-");
169 std::string arrayString=
"{-,1,-}";
170 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
171 Array<std::string> arrayVal_exp = tuple<std::string>(
"-",
"1",
"-");
176 std::string arrayString=
"{}";
177 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
178 Array<std::string> arrayVal_exp;
183 std::string arrayString=
"{,}";
185 [[maybe_unused]] Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString),
206 typedef typename Array<T>::size_type size_type;
222 out <<
"\nTest that a[i] == i ... ";
223 Array<T> a = generateArray<T>(
n);
224 bool local_success =
true;
225 for(
int i = 0; i <
n; ++i ) {
228 if (local_success) out <<
"passed\n";
229 else success =
false;
235 out <<
"\nTest that a.at(i) == i ...\n";
236 Array<T> a = generateArray<T>(
n);
237 bool local_success =
true;
238 for(
int i = 0; i <
n; ++i ) {
241 if (local_success) out <<
"passed\n";
242 else success =
false;
248 typedef typename ArrayView<T>::iterator iter_t;
250 iter_t iter = NIT::getNull();
252 ECHO(Array<T> a(n, as<T>(0)));
253 ECHO(ArrayView<T> av = a);
254 ECHO(iter = av.begin());
260 iter = NIT::getNull();
267 const RCP<Array<T> > a_rcp =
null;
268 const ArrayRCP<T> a_arcp =
arcp(a_rcp);
275 const RCP<const Array<T> > a_rcp =
null;
276 const ArrayRCP<const T> a_arcp =
arcp(a_rcp);
283 const Array<T> a_const = generateArray<T>(
n);
284 const RCP<Array<T> > a_rcp =
Teuchos::rcp(
new Array<T>(a_const));
285 const ArrayRCP<T> a_arcp =
arcp(a_rcp);
292 const Array<T> a_const = generateArray<T>(
n);
293 const RCP<const Array<T> > a_rcp =
Teuchos::rcp(
new Array<T>(a_const));
294 const ArrayRCP<const T> a_arcp =
arcp(a_rcp);
317 Array<T> a = generateArray<T>(
n);
325 const Array<T> a = generateArray<T>(
n);
335 Array<T> a = generateArray<T>(
n);
339 TEST_THROW(a_arcp[0], DanglingReferenceError);
341 (void)out; (void)success;
348 ArrayRCP<const T> a_arcp;
350 const Array<T> a = generateArray<T>(
n);
354 TEST_THROW(a_arcp[0], DanglingReferenceError);
356 (void)out; (void)success;
363 const Array<T> a = generateArray<T>(
n);
364 const std::vector<T> v = a.toVector();
372 const std::vector<T> v = a.toVector();
380 const ArrayView<T> av = a.view(0, 0);
388 const ArrayView<T> av = a(0, 0);
396 const ArrayView<const T> av = a.view(0, 0);
404 const ArrayView<T> av = a();
412 const ArrayView<const T> av = a();
420 { Array<T> a(n); av = a; }
421 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
422 TEST_THROW( av[0] = 0, DanglingReferenceError );
424 (void)out; (void)success;
431 ArrayView<const T> av;
432 { Array<T> a(n); av =
getConst(a); }
433 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
436 (void)out; (void)success;
444 { Array<T> a(n); av = a(); }
445 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
446 TEST_THROW( av[0] = 0, DanglingReferenceError );
448 (void)out; (void)success;
455 ArrayView<const T> av;
456 { Array<T> a(n); av =
getConst(a)(); }
457 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
460 (void)out; (void)success;
468 { Array<T> a(n); av = a(0,1); }
469 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
470 TEST_THROW( av[0] = 0, DanglingReferenceError );
472 (void)out; (void)success;
479 ArrayView<const T> av;
480 { Array<T> a(n); av =
getConst(a)(0,1); }
481 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
484 (void)out; (void)success;
490 typedef typename ArrayView<T>::iterator iter_t;
492 ECHO(ArrayView<T> av = a);
493 ECHO(iter_t iter = av.begin());
496 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
497 TEST_THROW( *iter = 0, DanglingReferenceError );
499 (void)iter; (void)out; (void)success;
506 typedef typename ArrayView<const T>::iterator iter_t;
508 ECHO(ArrayView<T> av = a);
509 ECHO(iter_t iter = av.begin());
512 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
515 (void)iter; (void)out; (void)success;
522 ECHO(std::vector<T> v);
531 Array<T> a = generateArray<T>(
n);
534 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
535 TEST_THROW( av[0] = 0, DanglingReferenceError );
537 (void)av; (void)out; (void)success;
544 Array<T> a = generateArray<T>(
n);
545 ArrayView<const T> av =
getConst(a);
547 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
550 (void)av; (void)out; (void)success;
557 const Array<T> a2{as<T>(1),as<T>(2),as<T>(3),as<T>(4)};
559 for (
typename Array<T>::size_type i=0; i < a2.size(); ++i) {
569 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
571 # define DEBUG_UNIT_TEST_GROUP( T )
573 #else // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
575 # define DEBUG_UNIT_TEST_GROUP( T )
577 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
580 #define UNIT_TEST_GROUP( T ) \
581 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, defaultConstruct, T ) \
582 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, sizedConstruct, T ) \
583 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, operatorBracket, T ) \
584 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constAt, T ) \
585 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter_before_block_end, T ) \
586 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPArray_to_ArrayRCP_null, T ) \
587 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPconstArray_to_ArrayRCP_null, T ) \
588 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPArray_to_ArrayRCP, T ) \
589 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPconstArray_to_ArrayRCP, T ) \
590 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP_null, T ) \
591 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP_null, T ) \
592 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP, T ) \
593 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP, T ) \
594 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP_dangling, T ) \
595 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP_dangling, T ) \
596 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, toVector, T ) \
597 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, toVector_empty, T ) \
598 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, view_empty_func, T ) \
599 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, view_empty_operator, T ) \
600 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, implicit_to_ArrayView_empty, T ) \
601 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_implicit, T ) \
602 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_implicit_const, T ) \
603 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_explicit, T ) \
604 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_explicit_const, T ) \
605 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_subview, T ) \
606 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_subview_const, T ) \
607 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter, T ) \
608 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter_const, T ) \
609 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, erase_empty, T ) \
610 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, structuralChangeArrayView, T ) \
611 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, structuralChangeArrayView_const, T ) \
612 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, initializerList, T ) \
613 DEBUG_UNIT_TEST_GROUP( T )
Dangling reference error exception class.
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
#define ECHO(statement)
Echo the given statement before it is executed.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
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.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
ArrayRCP< T > arcpFromArray(Array< T > &a)
Wrap an Array<T> object as a non-owning ArrayRCP<T> object.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
static std::string trimWhiteSpace(const std::string &str)
Trim whitespace from beginning and end of std::string.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Teuchos::Array< T > generateArray(const int n_in)
Base traits class for getting a properly initialized null pointer.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Test that two values are equal.
Default traits class that just returns typeid(T).name().
#define TEST_ARRAY_ELE_EQUALITY(a, i, val)
Assert that a[i] == val.
#define UNIT_TEST_GROUP(T)
Smart reference counting pointer class for automatic garbage collection.
Reference-counted smart pointer for managing arrays.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...