66 T outputOrdinal(
const T &t)
72 int outputOrdinal(
const char& t)
90 if (! is_same<T, double_type>::value) {
92 TYPE_CHAIN_A<double_type>(out);
105 if (! is_same<T, half_type>::value) {
107 TYPE_CHAIN_D<half_type>(out);
112 inline std::string
passfail(
bool result)
114 return ( result ?
"passed" :
"failed" );
118 template<
class Scalar>
119 bool testScalarTraits(
132 const Scalar nan = ST::nan();
134 out <<
"Type chain (ascending) : "; TYPE_CHAIN_A<Scalar>(out); out <<
"\n";
135 out <<
"Type chain (descending): "; TYPE_CHAIN_D<Scalar>(out); out <<
"\n";
139 out <<
"\nTesting that squareroot(NaN) == NaN! ...\n";
141 const Scalar sqrtNan = ST::squareroot(nan);
142 out <<
"squareroot("<<nan<<
") = " << sqrtNan <<
"\n";
146 out <<
"\nTesting that squareroot(-NaN) == NaN! ...\n";
148 const Scalar negNan = -nan;
149 const Scalar sqrtNegNan = ST::squareroot(negNan);
150 out <<
"squareroot("<<negNan<<
") = " << sqrtNegNan <<
"\n";
154 if (ST::isComplex ==
false)
156 out <<
"\nTesting that squareroot(-1) == NaN! ...\n";
158 const Scalar negOne = -ST::one();
159 const Scalar sqrtNegOne = ST::squareroot(negOne);
160 out <<
"squareroot("<<negOne<<
") = " << sqrtNegOne <<
"\n";
165 #ifdef HAVE_NUMERIC_LIMITS
167 out <<
"\nTesting that squareroot(quiet_NaN) == NaN! ...\n";
169 const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
170 const Scalar sqrtNan = ST::squareroot(nan);
174 out <<
"\nTesting that squareroot(signaling_NaN) == NaN! ...\n";
176 const Scalar nan = std::numeric_limits<Scalar>::signaling_NaN();
177 const Scalar sqrtNan = ST::squareroot(nan);
181 out <<
"\nTesting that squareroot(inf) == NaN! ...\n";
183 const Scalar inf = std::numeric_limits<Scalar>::infinity();
184 const Scalar sqrtInf = ST::squareroot(inf);
188 #endif // HAVE_NUMERIC_LIMITS
195 template<
class Ordinal>
196 bool testOrdinalTraits(
210 const Ordinal zero = OT::zero();
211 const Ordinal one = OT::one();
212 const Ordinal max = OT::max();
213 const Ordinal invalid = OT::invalid();
214 out <<
"\nmax() == " << outputOrdinal(max) <<
"\n";
215 out <<
"\ninvalid() == " << outputOrdinal(invalid) <<
"\n";
217 out <<
"\nTesting that zero() * one() == zero() ...\n";
219 const Ordinal zto = zero*one;
220 result = (zto == zero);
221 if (!result) success =
false;
223 <<
"zero*one = " << outputOrdinal(zto) <<
" == " << outputOrdinal(zero) <<
" : "
227 out <<
"\nTesting that one() * one() == one() ...\n";
229 const Ordinal oto = one*one;
230 result = (oto == one);
231 if (!result) success =
false;
233 <<
"one*one = " << outputOrdinal(oto) <<
" == " << outputOrdinal(one) <<
" : "
237 out <<
"\nTesting that one() + zero() == zero() + one() == one() ...\n";
239 const Ordinal opz = one+zero;
240 const Ordinal zpo = zero+one;
241 result = (opz == one) && (zpo == one);
242 if (!result) success =
false;
244 <<
"one+zero = " << outputOrdinal(opz) <<
" == zero+one = "
245 << outputOrdinal(zpo) <<
" == " << outputOrdinal(one) <<
" : "
249 out <<
"\nTesting that one() - one() == zero() ...\n";
251 const Ordinal omo = one-one;
252 result = (omo == zero);
253 if (!result) success =
false;
255 <<
"one-one = " << outputOrdinal(omo) <<
" == " << outputOrdinal(zero) <<
" : "
259 out <<
"\nTesting that zero() < one() <= max() ...\n";
261 result = (zero < one) && (one <= max) && (zero < max);
262 if (!result) success =
false;
264 <<
"(zero < one) = " << (zero < one) <<
" == "
265 <<
"(one <= max) = " << (one <= max) <<
" == "
266 <<
"(zero < max) = " << (zero < max) <<
" == "
271 out <<
"\nTesting that invalid() not in [zero(),max()]...\n";
273 result = !( (invalid > zero || invalid==zero) && (invalid <= max) );
274 if (!result) success =
false;
276 <<
"invalid in [zero,max] == false : " <<
passfail(result) <<
"\n";
287 int main(
int argc,
char* argv[] ) {
303 CommandLineProcessor clp(
false);
304 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
305 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
306 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
310 result = testScalarTraits<float>(*out);
311 if(!result) success =
false;
313 result = testScalarTraits<double>(*out);
314 if(!result) success =
false;
316 result = testOrdinalTraits<char>(*out);
317 if(!result) success =
false;
319 result = testOrdinalTraits<short int>(*out);
320 if(!result) success =
false;
322 result = testOrdinalTraits<int>(*out);
323 if(!result) success =
false;
325 result = testOrdinalTraits<long int>(*out);
326 if(!result) success =
false;
328 result = testOrdinalTraits<size_t>(*out);
329 if(!result) success =
false;
331 result = testOrdinalTraits<long long int>(*out);
332 if(!result) success =
false;
334 #ifdef HAVE_TEUCHOS___INT64
335 result = testOrdinalTraits<__int64>(*out);
336 if(!result) success =
false;
338 result = testOrdinalTraits<unsigned __int64>(*out);
339 if(!result) success =
false;
347 #ifdef HAVE_TEUCHOSCORE_QUADMATH
348 result = testScalarTraits<__float128>(*out);
349 if(!result) success =
false;
350 #endif // HAVE_TEUCHOSCORE_QUADMATH
352 #ifdef HAVE_TEUCHOS_QD
353 result = testScalarTraits<dd_real>(*out);
354 if(!result) success =
false;
355 result = testScalarTraits<qd_real>(*out);
356 if(!result) success =
false;
363 *out <<
"\nEnd Result: TEST PASSED\n" << std::endl;
365 *out <<
"\nEnd Result: TEST FAILED\n" << std::endl;
367 return ( success ? 0 : 1 );
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
#define TEUCHOS_TEST_EQUALITY_CONST(v1, v2, out, success)
Test that an object is equal to a given constant.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
const std::string passfail(const bool result)
Return "passed" or "failed".
This structure defines some basic traits for a scalar field type.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
Default is_equal traits class has value equal to false, indicating that T1 and T2 are not equal...
#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.
This structure defines some basic traits for the ordinal field type.
T doublePrecision
Typedef for double precision.
int main(int argc, char *argv[])
Utilities to make writing tests easier.
Defines basic traits for the ordinal field type.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
Defines basic traits for the scalar field type.
Smart reference counting pointer class for automatic garbage collection.
T halfPrecision
Typedef for half precision.
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...
Defines basic traits allowing evaluation of type equality.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
static std::string name()