|
Sacado Package Browser (Single Doxygen Collection)
Version of the Day
|
Go to the documentation of this file.
32 #ifndef FADUNITTESTS_HPP
33 #define FADUNITTESTS_HPP
43 #include <cppunit/extensions/HelperMacros.h>
45 #define COMPARE_VALUES(a, b) \
46 CPPUNIT_ASSERT( std::abs(a-b) < this->tol_a + this->tol_r*std::abs(a) );
48 #define COMPARE_FADS(a, b) \
49 CPPUNIT_ASSERT(a.size() == b.size()); \
50 CPPUNIT_ASSERT(a.hasFastAccess() == b.hasFastAccess()); \
51 COMPARE_VALUES(a.val(), b.val()); \
52 for (int i=0; i<a.size(); i++) { \
53 COMPARE_VALUES(a.dx(i), b.dx(i)); \
54 COMPARE_VALUES(a.fastAccessDx(i), b.fastAccessDx(i)); \
58 #define BINARY_OP_TEST(TESTNAME,OP) \
60 c_dfad = a_dfad OP b_dfad; \
61 c_fad = a_fad OP b_fad; \
62 COMPARE_FADS(c_dfad, c_fad); \
64 double val = urand.number(); \
65 c_dfad = a_dfad OP val; \
66 c_fad = a_fad OP val; \
67 COMPARE_FADS(c_dfad, c_fad); \
69 c_dfad = val OP b_dfad; \
70 c_fad = val OP b_fad; \
71 COMPARE_FADS(c_dfad, c_fad); \
74 #define RELOP_TEST(TESTNAME,OP) \
76 bool r1 = a_dfad OP b_dfad; \
77 bool r2 = a_fad OP b_fad; \
78 CPPUNIT_ASSERT(r1 == r2); \
80 double val = urand.number(); \
83 CPPUNIT_ASSERT(r1 == r2); \
87 CPPUNIT_ASSERT(r1 == r2); \
90 #define BINARY_FUNC_TEST(TESTNAME,FUNC) \
92 c_dfad = FUNC (a_dfad,b_dfad); \
93 c_fad = FUNC (a_fad,b_fad); \
94 COMPARE_FADS(c_dfad, c_fad); \
96 double val = urand.number(); \
97 c_dfad = FUNC (a_dfad,val); \
98 c_fad = FUNC (a_fad,val); \
99 COMPARE_FADS(c_dfad, c_fad); \
101 c_dfad = FUNC (val,b_dfad); \
102 c_fad = FUNC (val,b_fad); \
103 COMPARE_FADS(c_dfad, c_fad); \
106 #define UNARY_OP_TEST(TESTNAME,OP) \
108 c_dfad = OP a_dfad; \
110 COMPARE_FADS(c_dfad, c_fad); \
113 #define UNARY_FUNC_TEST(TESTNAME,FUNC) \
115 c_dfad = FUNC (a_dfad); \
116 c_fad = FUNC (a_fad); \
117 COMPARE_FADS(c_dfad, c_fad); \
120 #define UNARY_ASSIGNOP_TEST(TESTNAME,OP) \
124 COMPARE_FADS(c_dfad, c_fad); \
126 double val = urand.number(); \
129 COMPARE_FADS(c_dfad, c_fad); \
133 template <
class FadType,
class ScalarType>
192 ScalarType relative_tolerance);
239 template <
typename ScalarT>
261 FAD::Fad<ScalarType> aa_fad =
a_fad;
264 aa_dfad = aa_dfad +
b_dfad;
265 aa_fad = aa_fad +
b_fad;
271 FAD::Fad<ScalarType> aa_fad =
a_fad;
274 aa_dfad = aa_dfad -
b_dfad;
275 aa_fad = aa_fad -
b_fad;
281 FAD::Fad<ScalarType> aa_fad =
a_fad;
284 aa_dfad = aa_dfad *
b_dfad;
285 aa_fad = aa_fad *
b_fad;
291 FAD::Fad<ScalarType> aa_fad =
a_fad;
294 aa_dfad = aa_dfad /
b_dfad;
295 aa_fad = aa_fad /
b_fad;
318 template <
class FadType,
class ScalarType>
321 urand(), n(5), tol_a(1.0e-15), tol_r(1.0e-14) {}
323 template <
class FadType,
class ScalarType>
326 ScalarType relative_tolerance) :
329 tol_a(absolute_tolerance),
330 tol_r(relative_tolerance) {}
332 template <
class FadType,
class ScalarType>
336 val = urand.number();
338 a_fad = FAD::Fad<ScalarType>(n,
val);
340 val = urand.number();
342 b_fad = FAD::Fad<ScalarType>(n,
val);
344 for (
int i=0; i<n; i++) {
345 val = urand.number();
346 a_dfad.fastAccessDx(i) =
val;
347 a_fad.fastAccessDx(i) =
val;
349 val = urand.number();
350 b_dfad.fastAccessDx(i) =
val;
351 b_fad.fastAccessDx(i) =
val;
355 template <
class FadType,
class ScalarType>
359 template <
class FadType,
class ScalarType>
364 FadType aa_dfad = a_dfad + 1.0;
365 c_dfad =
max(aa_dfad, a_dfad);
367 for (
int i=0; i<n; i++) {
372 c_dfad =
max(a_dfad, aa_dfad);
374 for (
int i=0; i<n; i++) {
379 c_dfad =
max(a_dfad+1.0, a_dfad);
381 for (
int i=0; i<n; i++) {
386 c_dfad =
max(a_dfad, a_dfad+1.0);
388 for (
int i=0; i<n; i++) {
393 val = a_dfad.val() + 1;
394 c_dfad =
max(a_dfad,
val);
396 for (
int i=0; i<n; i++)
399 val = a_dfad.val() - 1;
400 c_dfad =
max(a_dfad,
val);
402 for (
int i=0; i<n; i++) {
407 val = b_dfad.val() + 1;
408 c_dfad =
max(
val, b_dfad);
410 for (
int i=0; i<n; i++)
413 val = b_dfad.val() - 1;
414 c_dfad =
max(
val, b_dfad);
416 for (
int i=0; i<n; i++) {
422 template <
class FadType,
class ScalarType>
427 FadType aa_dfad = a_dfad - 1.0;
428 c_dfad =
min(aa_dfad, a_dfad);
430 for (
int i=0; i<n; i++) {
435 c_dfad =
min(a_dfad, aa_dfad);
437 for (
int i=0; i<n; i++) {
442 val = a_dfad.val() - 1;
443 c_dfad =
min(a_dfad,
val);
445 for (
int i=0; i<n; i++)
448 val = a_dfad.val() + 1;
449 c_dfad =
min(a_dfad,
val);
451 for (
int i=0; i<n; i++) {
456 val = b_dfad.val() - 1;
457 c_dfad =
min(
val, b_dfad);
459 for (
int i=0; i<n; i++)
462 val = b_dfad.val() + 1;
463 c_dfad =
min(
val, b_dfad);
465 for (
int i=0; i<n; i++) {
471 #undef COMPARE_VALUES
474 #endif // FADUNITTESTS_HPP
RELOP_TEST(testNotEquals, !=)
UNARY_FUNC_TEST(testExp, exp)
Sacado::Random< ScalarType > urand
CPPUNIT_TEST(testMultiplication)
BINARY_OP_TEST(testSubtraction, -)
UNARY_FUNC_TEST(testLog, log)
CPPUNIT_TEST(testUnaryPlus)
UNARY_FUNC_TEST(testATan, atan)
UNARY_FUNC_TEST(testAbs, abs)
CPPUNIT_TEST(testTimesEquals)
CPPUNIT_TEST(testLessThan)
UNARY_FUNC_TEST(testSqrt, sqrt)
CPPUNIT_TEST(testGreaterThan)
UNARY_ASSIGNOP_TEST(testDivideEquals,/=)
UNARY_OP_TEST(testUnaryPlus,+)
UNARY_FUNC_TEST(testCosh, cosh)
UNARY_OP_TEST(testUnaryMinus, -)
UNARY_FUNC_TEST(testTan, tan)
CPPUNIT_TEST(testNotEquals)
BINARY_OP_TEST(testAddition,+)
UNARY_FUNC_TEST(testSinh, sinh)
UNARY_FUNC_TEST(testACos, acos)
UNARY_ASSIGNOP_TEST(testTimesEquals, *=)
RELOP_TEST(testLessThanOrEquals,<=)
UNARY_ASSIGNOP_TEST(testPlusEquals,+=)
UNARY_ASSIGNOP_TEST(testMinusEquals, -=)
RELOP_TEST(testGreaterThanOrEquals, >=)
UNARY_FUNC_TEST(testTanh, tanh)
RELOP_TEST(testLessThan,<)
BINARY_OP_TEST(testDivision,/)
CPPUNIT_TEST(testTimesLR)
BINARY_OP_TEST(testMultiplication, *)
CPPUNIT_TEST(testUnaryMinus)
ScalarT composite1(const ScalarT &a, const ScalarT &b)
FAD::Fad< ScalarType > a_fad
CPPUNIT_TEST(testDivideLR)
CPPUNIT_TEST(testPlusEquals)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
UNARY_FUNC_TEST(testSin, sin)
RELOP_TEST(testGreaterThan, >)
#define COMPARE_FADS(a, b)
CPPUNIT_TEST_SUITE(FadOpsUnitTest)
FAD::Fad< ScalarType > b_fad
Sacado::Fad::DFad< double > FadType
CPPUNIT_TEST(testMinusLR)
CPPUNIT_TEST(testMinusEquals)
CPPUNIT_TEST(testDivideEquals)
pow(expr1.val(), expr2.val())
CPPUNIT_TEST(testAddition)
#define COMPARE_VALUES(a, b)
UNARY_FUNC_TEST(testASin, asin)
BINARY_FUNC_TEST(testPow, pow)
UNARY_FUNC_TEST(testLog10, log10)
UNARY_FUNC_TEST(testCos, cos)
CPPUNIT_TEST(testDivision)
FAD::Fad< ScalarType > c_fad
RELOP_TEST(testEquals,==)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
UNARY_FUNC_TEST(testFAbs, fabs)
CPPUNIT_TEST(testLessThanOrEquals)
CPPUNIT_TEST(testSubtraction)
CPPUNIT_TEST(testComposite1)
CPPUNIT_TEST(testGreaterThanOrEquals)