32 T outputOrdinal(
const T &t)
38 int outputOrdinal(
const char& t)
55 if (! std::is_same_v<T, double_type>) {
57 TYPE_CHAIN_A<double_type>(out);
69 if (! std::is_same_v<T, half_type>) {
71 TYPE_CHAIN_D<half_type>(out);
76 inline std::string
passfail(
bool result)
78 return ( result ?
"passed" :
"failed" );
82 template<
class Scalar>
83 bool testScalarTraits(
96 const Scalar nan = ST::nan();
98 out <<
"Type chain (ascending) : "; TYPE_CHAIN_A<Scalar>(out); out <<
"\n";
99 out <<
"Type chain (descending): "; TYPE_CHAIN_D<Scalar>(out); out <<
"\n";
103 out <<
"\nTesting that squareroot(NaN) == NaN! ...\n";
105 const Scalar sqrtNan = ST::squareroot(nan);
106 out <<
"squareroot("<<nan<<
") = " << sqrtNan <<
"\n";
110 out <<
"\nTesting that squareroot(-NaN) == NaN! ...\n";
112 const Scalar negNan = -nan;
113 const Scalar sqrtNegNan = ST::squareroot(negNan);
114 out <<
"squareroot("<<negNan<<
") = " << sqrtNegNan <<
"\n";
118 if (ST::isComplex ==
false)
120 out <<
"\nTesting that squareroot(-1) == NaN! ...\n";
122 const Scalar negOne = -ST::one();
123 const Scalar sqrtNegOne = ST::squareroot(negOne);
124 out <<
"squareroot("<<negOne<<
") = " << sqrtNegOne <<
"\n";
129 #ifdef HAVE_NUMERIC_LIMITS
131 out <<
"\nTesting that squareroot(quiet_NaN) == NaN! ...\n";
133 const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
134 const Scalar sqrtNan = ST::squareroot(nan);
138 out <<
"\nTesting that squareroot(signaling_NaN) == NaN! ...\n";
140 const Scalar nan = std::numeric_limits<Scalar>::signaling_NaN();
141 const Scalar sqrtNan = ST::squareroot(nan);
145 out <<
"\nTesting that squareroot(inf) == NaN! ...\n";
147 const Scalar inf = std::numeric_limits<Scalar>::infinity();
148 const Scalar sqrtInf = ST::squareroot(inf);
152 #endif // HAVE_NUMERIC_LIMITS
159 template<
class Ordinal>
160 bool testOrdinalTraits(
174 const Ordinal zero = OT::zero();
175 const Ordinal one = OT::one();
176 const Ordinal max = OT::max();
177 const Ordinal invalid = OT::invalid();
178 out <<
"\nmax() == " << outputOrdinal(max) <<
"\n";
179 out <<
"\ninvalid() == " << outputOrdinal(invalid) <<
"\n";
181 out <<
"\nTesting that zero() * one() == zero() ...\n";
183 const Ordinal zto = zero*one;
184 result = (zto == zero);
185 if (!result) success =
false;
187 <<
"zero*one = " << outputOrdinal(zto) <<
" == " << outputOrdinal(zero) <<
" : "
191 out <<
"\nTesting that one() * one() == one() ...\n";
193 const Ordinal oto = one*one;
194 result = (oto == one);
195 if (!result) success =
false;
197 <<
"one*one = " << outputOrdinal(oto) <<
" == " << outputOrdinal(one) <<
" : "
201 out <<
"\nTesting that one() + zero() == zero() + one() == one() ...\n";
203 const Ordinal opz = one+zero;
204 const Ordinal zpo = zero+one;
205 result = (opz == one) && (zpo == one);
206 if (!result) success =
false;
208 <<
"one+zero = " << outputOrdinal(opz) <<
" == zero+one = "
209 << outputOrdinal(zpo) <<
" == " << outputOrdinal(one) <<
" : "
213 out <<
"\nTesting that one() - one() == zero() ...\n";
215 const Ordinal omo = one-one;
216 result = (omo == zero);
217 if (!result) success =
false;
219 <<
"one-one = " << outputOrdinal(omo) <<
" == " << outputOrdinal(zero) <<
" : "
223 out <<
"\nTesting that zero() < one() <= max() ...\n";
225 result = (zero < one) && (one <= max) && (zero < max);
226 if (!result) success =
false;
228 <<
"(zero < one) = " << (zero < one) <<
" == "
229 <<
"(one <= max) = " << (one <= max) <<
" == "
230 <<
"(zero < max) = " << (zero < max) <<
" == "
235 out <<
"\nTesting that invalid() not in [zero(),max()]...\n";
237 result = !( (invalid > zero || invalid==zero) && (invalid <= max) );
238 if (!result) success =
false;
240 <<
"invalid in [zero,max] == false : " <<
passfail(result) <<
"\n";
251 int main(
int argc,
char* argv[] ) {
267 CommandLineProcessor clp(
false);
268 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
269 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
270 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
274 result = testScalarTraits<float>(*out);
275 if(!result) success =
false;
277 result = testScalarTraits<double>(*out);
278 if(!result) success =
false;
280 result = testOrdinalTraits<char>(*out);
281 if(!result) success =
false;
283 result = testOrdinalTraits<short int>(*out);
284 if(!result) success =
false;
286 result = testOrdinalTraits<int>(*out);
287 if(!result) success =
false;
289 result = testOrdinalTraits<long int>(*out);
290 if(!result) success =
false;
292 result = testOrdinalTraits<size_t>(*out);
293 if(!result) success =
false;
295 result = testOrdinalTraits<long long int>(*out);
296 if(!result) success =
false;
298 #ifdef HAVE_TEUCHOS___INT64
299 result = testOrdinalTraits<__int64>(*out);
300 if(!result) success =
false;
302 result = testOrdinalTraits<unsigned __int64>(*out);
303 if(!result) success =
false;
306 #ifdef HAVE_TEUCHOS_COMPLEX
307 result = testScalarTraits<std::complex<double> >(*out);
308 if(!result) success =
false;
310 result = testScalarTraits<std::complex<float> >(*out);
311 if(!result) success =
false;
312 #endif // HAVE_TEUCHOS_COMPLEX
314 #ifdef HAVE_TEUCHOSCORE_KOKKOS
315 result = testScalarTraits<Kokkos::complex<double> >(*out);
316 if(!result) success =
false;
318 result = testScalarTraits<Kokkos::complex<float> >(*out);
319 if(!result) success =
false;
320 #endif // HAVE_TEUCHOSCORE_KOKKOS
322 #ifdef HAVE_TEUCHOSCORE_QUADMATH
323 result = testScalarTraits<__float128>(*out);
324 if(!result) success =
false;
325 #endif // HAVE_TEUCHOSCORE_QUADMATH
327 #ifdef HAVE_TEUCHOS_QD
328 result = testScalarTraits<dd_real>(*out);
329 if(!result) success =
false;
330 result = testScalarTraits<qd_real>(*out);
331 if(!result) success =
false;
338 *out <<
"\nEnd Result: TEST PASSED\n" << std::endl;
340 *out <<
"\nEnd Result: TEST FAILED\n" << std::endl;
342 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()