27 using Teuchos::arcpFromArray;
31 using Teuchos::fromStringToArray;
45 std::string(
"Array(double)"));
53 std::string arrayString=
"{}";
54 std::istringstream arrayStream(arrayString);
55 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
56 Array<std::string> arrayStreamVal;
57 arrayStream >> arrayStreamVal;
58 Array<std::string> arrayVal_exp;
64 std::string arrayString =
"{ a, b, c, d }";
65 std::istringstream arrayStream(arrayString);
66 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
67 Array<std::string> arrayStreamVal;
68 arrayStream >> arrayStreamVal;
69 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"a",
"b",
"c",
"d" );
75 std::string arrayString =
"{ (a), b, c, (d) }";
76 std::istringstream arrayStream(arrayString);
77 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
78 Array<std::string> arrayStreamVal;
79 arrayStream >> arrayStreamVal;
80 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"(a)",
"b",
"c",
"(d)" );
86 std::string arrayString =
"{ (a ), b, c, (d ) }";
87 std::istringstream arrayStream(arrayString);
88 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
89 Array<std::string> arrayStreamVal;
90 arrayStream >> arrayStreamVal;
91 Array<std::string> arrayVal_exp = Teuchos::tuple<std::string>(
"(a )",
"b",
"c",
"(d )" );
108 TEST_THROW(fromStringToArray<std::string>(
"{ a, b, c"),
109 InvalidArrayStringRepresentation);
110 TEST_THROW(fromStringToArray<std::string>(
"a, b, c}"),
111 InvalidArrayStringRepresentation);
112 TEST_THROW(fromStringToArray<std::string>(
"a, b, c"),
113 InvalidArrayStringRepresentation);
121 std::string arrayString=
"{-}";
122 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
123 Array<std::string> arrayVal_exp = tuple<std::string>(
"-");
128 std::string arrayString=
"{-,-}";
129 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
130 Array<std::string> arrayVal_exp = tuple<std::string>(
"-",
"-");
135 std::string arrayString=
"{-,1,-}";
136 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
137 Array<std::string> arrayVal_exp = tuple<std::string>(
"-",
"1",
"-");
142 std::string arrayString=
"{}";
143 Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString);
144 Array<std::string> arrayVal_exp;
149 std::string arrayString=
"{,}";
151 [[maybe_unused]] Array<std::string> arrayVal = fromStringToArray<std::string>(arrayString),
172 typedef typename Array<T>::size_type size_type;
188 out <<
"\nTest that a[i] == i ... ";
189 Array<T> a = generateArray<T>(
n);
190 bool local_success =
true;
191 for(
int i = 0; i <
n; ++i ) {
194 if (local_success) out <<
"passed\n";
195 else success =
false;
201 out <<
"\nTest that a.at(i) == i ...\n";
202 Array<T> a = generateArray<T>(
n);
203 bool local_success =
true;
204 for(
int i = 0; i <
n; ++i ) {
207 if (local_success) out <<
"passed\n";
208 else success =
false;
214 typedef typename ArrayView<T>::iterator iter_t;
216 iter_t iter = NIT::getNull();
218 ECHO(Array<T> a(n, as<T>(0)));
219 ECHO(ArrayView<T> av = a);
220 ECHO(iter = av.begin());
226 iter = NIT::getNull();
233 const RCP<Array<T> > a_rcp =
null;
234 const ArrayRCP<T> a_arcp =
arcp(a_rcp);
241 const RCP<const Array<T> > a_rcp =
null;
242 const ArrayRCP<const T> a_arcp =
arcp(a_rcp);
249 const Array<T> a_const = generateArray<T>(
n);
250 const RCP<Array<T> > a_rcp =
Teuchos::rcp(
new Array<T>(a_const));
251 const ArrayRCP<T> a_arcp =
arcp(a_rcp);
258 const Array<T> a_const = generateArray<T>(
n);
259 const RCP<const Array<T> > a_rcp =
Teuchos::rcp(
new Array<T>(a_const));
260 const ArrayRCP<const T> a_arcp =
arcp(a_rcp);
283 Array<T> a = generateArray<T>(
n);
291 const Array<T> a = generateArray<T>(
n);
301 Array<T> a = generateArray<T>(
n);
305 TEST_THROW(a_arcp[0], DanglingReferenceError);
307 (void)out; (void)success;
314 ArrayRCP<const T> a_arcp;
316 const Array<T> a = generateArray<T>(
n);
320 TEST_THROW(a_arcp[0], DanglingReferenceError);
322 (void)out; (void)success;
329 const Array<T> a = generateArray<T>(
n);
330 const std::vector<T> v = a.toVector();
338 const std::vector<T> v = a.toVector();
346 const ArrayView<T> av = a.view(0, 0);
354 const ArrayView<T> av = a(0, 0);
362 const ArrayView<const T> av = a.view(0, 0);
370 const ArrayView<T> av = a();
378 const ArrayView<const T> av = a();
386 { Array<T> a(n); av = a; }
387 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
388 TEST_THROW( av[0] = 0, DanglingReferenceError );
390 (void)out; (void)success;
397 ArrayView<const T> av;
398 { Array<T> a(n); av =
getConst(a); }
399 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
402 (void)out; (void)success;
410 { Array<T> a(n); av = a(); }
411 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
412 TEST_THROW( av[0] = 0, DanglingReferenceError );
414 (void)out; (void)success;
421 ArrayView<const T> av;
422 { Array<T> a(n); av =
getConst(a)(); }
423 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
426 (void)out; (void)success;
434 { Array<T> a(n); av = a(0,1); }
435 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
436 TEST_THROW( av[0] = 0, DanglingReferenceError );
438 (void)out; (void)success;
445 ArrayView<const T> av;
446 { Array<T> a(n); av =
getConst(a)(0,1); }
447 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
450 (void)out; (void)success;
456 typedef typename ArrayView<T>::iterator iter_t;
458 ECHO(ArrayView<T> av = a);
459 ECHO(iter_t iter = av.begin());
462 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
463 TEST_THROW( *iter = 0, DanglingReferenceError );
465 (void)iter; (void)out; (void)success;
472 typedef typename ArrayView<const T>::iterator iter_t;
474 ECHO(ArrayView<T> av = a);
475 ECHO(iter_t iter = av.begin());
478 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
481 (void)iter; (void)out; (void)success;
488 ECHO(std::vector<T> v);
497 Array<T> a = generateArray<T>(
n);
500 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
501 TEST_THROW( av[0] = 0, DanglingReferenceError );
503 (void)av; (void)out; (void)success;
510 Array<T> a = generateArray<T>(
n);
511 ArrayView<const T> av =
getConst(a);
513 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
516 (void)av; (void)out; (void)success;
523 const Array<T> a2{as<T>(1),as<T>(2),as<T>(3),as<T>(4)};
525 for (
typename Array<T>::size_type i=0; i < a2.size(); ++i) {
535 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
537 # define DEBUG_UNIT_TEST_GROUP( T )
539 #else // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
541 # define DEBUG_UNIT_TEST_GROUP( T )
543 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
546 #define UNIT_TEST_GROUP( T ) \
547 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, defaultConstruct, T ) \
548 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, sizedConstruct, T ) \
549 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, operatorBracket, T ) \
550 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constAt, T ) \
551 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter_before_block_end, T ) \
552 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPArray_to_ArrayRCP_null, T ) \
553 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPconstArray_to_ArrayRCP_null, T ) \
554 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPArray_to_ArrayRCP, T ) \
555 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, RCPconstArray_to_ArrayRCP, T ) \
556 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP_null, T ) \
557 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP_null, T ) \
558 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP, T ) \
559 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP, T ) \
560 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, Array_to_ArrayRCP_dangling, T ) \
561 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, constArray_to_ArrayRCP_dangling, T ) \
562 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, toVector, T ) \
563 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, toVector_empty, T ) \
564 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, view_empty_func, T ) \
565 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, view_empty_operator, T ) \
566 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, implicit_to_ArrayView_empty, T ) \
567 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_implicit, T ) \
568 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_implicit_const, T ) \
569 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_explicit, T ) \
570 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_explicit_const, T ) \
571 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_subview, T ) \
572 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayView_subview_const, T ) \
573 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter, T ) \
574 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, danglingArrayViewIter_const, T ) \
575 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, erase_empty, T ) \
576 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, structuralChangeArrayView, T ) \
577 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, structuralChangeArrayView_const, T ) \
578 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Array, initializerList, T ) \
579 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...