65 T outputOrdinal(
const T &t)
71 int outputOrdinal(
const char& t)
88 if (! std::is_same_v<T, double_type>) {
90 TYPE_CHAIN_A<double_type>(out);
102 if (! std::is_same_v<T, half_type>) {
104 TYPE_CHAIN_D<half_type>(out);
109 inline std::string
passfail(
bool result)
111 return ( result ?
"passed" :
"failed" );
115 template<
class Scalar>
116 bool testScalarTraits(
129 const Scalar nan = ST::nan();
131 out <<
"Type chain (ascending) : "; TYPE_CHAIN_A<Scalar>(out); out <<
"\n";
132 out <<
"Type chain (descending): "; TYPE_CHAIN_D<Scalar>(out); out <<
"\n";
136 out <<
"\nTesting that squareroot(NaN) == NaN! ...\n";
138 const Scalar sqrtNan = ST::squareroot(nan);
139 out <<
"squareroot("<<nan<<
") = " << sqrtNan <<
"\n";
143 out <<
"\nTesting that squareroot(-NaN) == NaN! ...\n";
145 const Scalar negNan = -nan;
146 const Scalar sqrtNegNan = ST::squareroot(negNan);
147 out <<
"squareroot("<<negNan<<
") = " << sqrtNegNan <<
"\n";
151 if (ST::isComplex ==
false)
153 out <<
"\nTesting that squareroot(-1) == NaN! ...\n";
155 const Scalar negOne = -ST::one();
156 const Scalar sqrtNegOne = ST::squareroot(negOne);
157 out <<
"squareroot("<<negOne<<
") = " << sqrtNegOne <<
"\n";
162 #ifdef HAVE_NUMERIC_LIMITS
164 out <<
"\nTesting that squareroot(quiet_NaN) == NaN! ...\n";
166 const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
167 const Scalar sqrtNan = ST::squareroot(nan);
171 out <<
"\nTesting that squareroot(signaling_NaN) == NaN! ...\n";
173 const Scalar nan = std::numeric_limits<Scalar>::signaling_NaN();
174 const Scalar sqrtNan = ST::squareroot(nan);
178 out <<
"\nTesting that squareroot(inf) == NaN! ...\n";
180 const Scalar inf = std::numeric_limits<Scalar>::infinity();
181 const Scalar sqrtInf = ST::squareroot(inf);
185 #endif // HAVE_NUMERIC_LIMITS
192 template<
class Ordinal>
193 bool testOrdinalTraits(
207 const Ordinal zero = OT::zero();
208 const Ordinal one = OT::one();
209 const Ordinal max = OT::max();
210 const Ordinal invalid = OT::invalid();
211 out <<
"\nmax() == " << outputOrdinal(max) <<
"\n";
212 out <<
"\ninvalid() == " << outputOrdinal(invalid) <<
"\n";
214 out <<
"\nTesting that zero() * one() == zero() ...\n";
216 const Ordinal zto = zero*one;
217 result = (zto == zero);
218 if (!result) success =
false;
220 <<
"zero*one = " << outputOrdinal(zto) <<
" == " << outputOrdinal(zero) <<
" : "
224 out <<
"\nTesting that one() * one() == one() ...\n";
226 const Ordinal oto = one*one;
227 result = (oto == one);
228 if (!result) success =
false;
230 <<
"one*one = " << outputOrdinal(oto) <<
" == " << outputOrdinal(one) <<
" : "
234 out <<
"\nTesting that one() + zero() == zero() + one() == one() ...\n";
236 const Ordinal opz = one+zero;
237 const Ordinal zpo = zero+one;
238 result = (opz == one) && (zpo == one);
239 if (!result) success =
false;
241 <<
"one+zero = " << outputOrdinal(opz) <<
" == zero+one = "
242 << outputOrdinal(zpo) <<
" == " << outputOrdinal(one) <<
" : "
246 out <<
"\nTesting that one() - one() == zero() ...\n";
248 const Ordinal omo = one-one;
249 result = (omo == zero);
250 if (!result) success =
false;
252 <<
"one-one = " << outputOrdinal(omo) <<
" == " << outputOrdinal(zero) <<
" : "
256 out <<
"\nTesting that zero() < one() <= max() ...\n";
258 result = (zero < one) && (one <= max) && (zero < max);
259 if (!result) success =
false;
261 <<
"(zero < one) = " << (zero < one) <<
" == "
262 <<
"(one <= max) = " << (one <= max) <<
" == "
263 <<
"(zero < max) = " << (zero < max) <<
" == "
268 out <<
"\nTesting that invalid() not in [zero(),max()]...\n";
270 result = !( (invalid > zero || invalid==zero) && (invalid <= max) );
271 if (!result) success =
false;
273 <<
"invalid in [zero,max] == false : " <<
passfail(result) <<
"\n";
284 int main(
int argc,
char* argv[] ) {
300 CommandLineProcessor clp(
false);
301 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
302 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
303 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
307 result = testScalarTraits<float>(*out);
308 if(!result) success =
false;
310 result = testScalarTraits<double>(*out);
311 if(!result) success =
false;
313 result = testOrdinalTraits<char>(*out);
314 if(!result) success =
false;
316 result = testOrdinalTraits<short int>(*out);
317 if(!result) success =
false;
319 result = testOrdinalTraits<int>(*out);
320 if(!result) success =
false;
322 result = testOrdinalTraits<long int>(*out);
323 if(!result) success =
false;
325 result = testOrdinalTraits<size_t>(*out);
326 if(!result) success =
false;
328 result = testOrdinalTraits<long long int>(*out);
329 if(!result) success =
false;
331 #ifdef HAVE_TEUCHOS___INT64
332 result = testOrdinalTraits<__int64>(*out);
333 if(!result) success =
false;
335 result = testOrdinalTraits<unsigned __int64>(*out);
336 if(!result) success =
false;
339 #ifdef HAVE_TEUCHOS_COMPLEX
340 result = testScalarTraits<std::complex<double> >(*out);
341 if(!result) success =
false;
343 result = testScalarTraits<std::complex<float> >(*out);
344 if(!result) success =
false;
345 #endif // HAVE_TEUCHOS_COMPLEX
347 #ifdef HAVE_TEUCHOSCORE_KOKKOS
348 result = testScalarTraits<Kokkos::complex<double> >(*out);
349 if(!result) success =
false;
351 result = testScalarTraits<Kokkos::complex<float> >(*out);
352 if(!result) success =
false;
353 #endif // HAVE_TEUCHOSCORE_KOKKOS
355 #ifdef HAVE_TEUCHOSCORE_QUADMATH
356 result = testScalarTraits<__float128>(*out);
357 if(!result) success =
false;
358 #endif // HAVE_TEUCHOSCORE_QUADMATH
360 #ifdef HAVE_TEUCHOS_QD
361 result = testScalarTraits<dd_real>(*out);
362 if(!result) success =
false;
363 result = testScalarTraits<qd_real>(*out);
364 if(!result) success =
false;
371 *out <<
"\nEnd Result: TEST PASSED\n" << std::endl;
373 *out <<
"\nEnd Result: TEST FAILED\n" << std::endl;
375 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 ...
#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...
Class that helps parse command line input arguments from (argc,argv[]) and set options.
static std::string name()