00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef HERMITEUNITTESTS_HPP
00033 #define HERMITEUNITTESTS_HPP
00034
00035
00036 #include "Sacado.hpp"
00037 #include "Sacado_Random.hpp"
00038 #include "Sacado_PCE_OrthogPoly.hpp"
00039 #include "Stokhos_HermiteEBasis.hpp"
00040
00041 typedef Stokhos::HermiteEBasis<double> basis_type;
00042 typedef Sacado::PCE::OrthogPoly<double>::expansion_type exp_type;
00043 typedef Sacado::PCE::OrthogPoly<double> pce_type;
00044
00045
00046 #include <cppunit/extensions/HelperMacros.h>
00047
00048 #define BINARY_OP_TEST(TESTNAME,OP) \
00049 void TESTNAME () { \
00050 cc = ac OP bc; \
00051 c = a OP b; \
00052 comparePCEs(cc, c); \
00053 \
00054 cc = ac OP b; \
00055 c = a OP b; \
00056 comparePCEs(cc, c); \
00057 \
00058 cc = a OP bc; \
00059 c = a OP b; \
00060 comparePCEs(cc, c); \
00061 }
00062
00063 #define RELOP_TEST(TESTNAME,OP) \
00064 void TESTNAME () { \
00065 bool r1 = ac OP bc; \
00066 bool r2 = a OP b; \
00067 CPPUNIT_ASSERT(r1 == r2); \
00068 \
00069 r1 = ac OP b; \
00070 r2 = a OP b; \
00071 CPPUNIT_ASSERT(r1 == r2); \
00072 \
00073 r1 = a OP bc; \
00074 r2 = a OP b; \
00075 CPPUNIT_ASSERT(r1 == r2); \
00076 }
00077
00078 #define BINARY_FUNC_TEST(TESTNAME,FUNC) \
00079 void TESTNAME () { \
00080 cc = FUNC (ac, bc); \
00081 c = FUNC (a, b); \
00082 comparePCEs(cc, c); \
00083 \
00084 cc = FUNC (ac, b); \
00085 c = FUNC (a, b); \
00086 comparePCEs(cc, c); \
00087 \
00088 cc = FUNC (a, bc); \
00089 c = FUNC (a, b); \
00090 comparePCEs(cc, c); \
00091 }
00092
00093 #define UNARY_OP_TEST(TESTNAME,OP) \
00094 void TESTNAME () { \
00095 cc = OP ac; \
00096 c = OP a; \
00097 comparePCEs(cc, c); \
00098 }
00099
00100 #define UNARY_FUNC_TEST(TESTNAME,FUNC) \
00101 void TESTNAME () { \
00102 cc = FUNC (ac); \
00103 c = FUNC (a); \
00104 comparePCEs(cc, c); \
00105 }
00106
00107 #define UNARY_ASSIGNOP_TEST(TESTNAME,OP) \
00108 void TESTNAME () { \
00109 cc OP ac; \
00110 c OP a; \
00111 comparePCEs(cc, c); \
00112 \
00113 cc OP a; \
00114 c OP a; \
00115 comparePCEs(cc, c); \
00116 }
00117
00118
00119 class HermiteUnitTest : public CppUnit::TestFixture {
00120
00121 CPPUNIT_TEST_SUITE( HermiteUnitTest );
00122
00123 CPPUNIT_TEST(testAddition);
00124 CPPUNIT_TEST(testSubtraction);
00125 CPPUNIT_TEST(testMultiplication);
00126 CPPUNIT_TEST(testDivision);
00127
00128 CPPUNIT_TEST(testEquals);
00129 CPPUNIT_TEST(testNotEquals);
00130 CPPUNIT_TEST(testLessThanOrEquals);
00131 CPPUNIT_TEST(testGreaterThanOrEquals);
00132 CPPUNIT_TEST(testLessThan);
00133 CPPUNIT_TEST(testGreaterThan);
00134
00135 CPPUNIT_TEST(testPow);
00136
00137 CPPUNIT_TEST(testUnaryPlus);
00138 CPPUNIT_TEST(testUnaryMinus);
00139
00140 CPPUNIT_TEST(testExp);
00141 CPPUNIT_TEST(testLog);
00142 CPPUNIT_TEST(testLog10);
00143 CPPUNIT_TEST(testSqrt);
00144 CPPUNIT_TEST(testCos);
00145 CPPUNIT_TEST(testSin);
00146 CPPUNIT_TEST(testTan);
00147 CPPUNIT_TEST(testACos);
00148 CPPUNIT_TEST(testASin);
00149 CPPUNIT_TEST(testATan);
00150 CPPUNIT_TEST(testCosh);
00151 CPPUNIT_TEST(testSinh);
00152 CPPUNIT_TEST(testTanh);
00153 CPPUNIT_TEST(testAbs);
00154 CPPUNIT_TEST(testFAbs);
00155
00156 CPPUNIT_TEST(testPlusEquals);
00157 CPPUNIT_TEST(testMinusEquals);
00158 CPPUNIT_TEST(testTimesEquals);
00159 CPPUNIT_TEST(testDivideEquals);
00160
00161 CPPUNIT_TEST(testComposite1);
00162
00163 CPPUNIT_TEST_SUITE_END();
00164
00165 public:
00166
00167 HermiteUnitTest();
00168
00169 HermiteUnitTest(double absolute_tolerance,
00170 double relative_tolerance);
00171
00172 void setUp();
00173
00174 void tearDown();
00175
00176
00177 void comparePCEs(const pce_type& xc, double x);
00178
00179
00180 void compareDoubles(double a, double b);
00181
00182 BINARY_OP_TEST(testAddition, +);
00183 BINARY_OP_TEST(testSubtraction, -);
00184 BINARY_OP_TEST(testMultiplication, *);
00185 BINARY_OP_TEST(testDivision, /);
00186
00187 RELOP_TEST(testEquals, ==);
00188 RELOP_TEST(testNotEquals, !=);
00189 RELOP_TEST(testLessThanOrEquals, <=);
00190 RELOP_TEST(testGreaterThanOrEquals, >=);
00191 RELOP_TEST(testLessThan, <);
00192 RELOP_TEST(testGreaterThan, >);
00193
00194 BINARY_FUNC_TEST(testPow, pow);
00195
00196 UNARY_OP_TEST(testUnaryPlus, +);
00197 UNARY_OP_TEST(testUnaryMinus, -);
00198
00199 UNARY_FUNC_TEST(testExp, exp);
00200 UNARY_FUNC_TEST(testLog, log);
00201 UNARY_FUNC_TEST(testLog10, log10);
00202 UNARY_FUNC_TEST(testSqrt, sqrt);
00203 UNARY_FUNC_TEST(testCos, cos);
00204 UNARY_FUNC_TEST(testSin, sin);
00205 UNARY_FUNC_TEST(testTan, tan);
00206 UNARY_FUNC_TEST(testACos, acos);
00207 UNARY_FUNC_TEST(testASin, asin);
00208 UNARY_FUNC_TEST(testATan, atan);
00209 UNARY_FUNC_TEST(testCosh, cosh);
00210 UNARY_FUNC_TEST(testSinh, sinh);
00211 UNARY_FUNC_TEST(testTanh, tanh);
00212 UNARY_FUNC_TEST(testAbs, fabs);
00213 UNARY_FUNC_TEST(testFAbs, fabs);
00214
00215 UNARY_ASSIGNOP_TEST(testPlusEquals, +=);
00216 UNARY_ASSIGNOP_TEST(testMinusEquals, -=);
00217 UNARY_ASSIGNOP_TEST(testTimesEquals, *=);
00218 UNARY_ASSIGNOP_TEST(testDivideEquals, /=);
00219
00220 template <typename ScalarT>
00221 ScalarT composite1(const ScalarT& a, const ScalarT& b) {
00222 ScalarT t1 = 3. * a + sin(b) / log(fabs(a - b * 7.));
00223 ScalarT t2 = 1.0e3;
00224 ScalarT t3 = 5.7e4;
00225 ScalarT t4 = 3.2e5;
00226 t1 *= cos(a + exp(t1)) / 6. - tan(t1*sqrt(fabs(a * log10(fabs(b)))));
00227 t1 -= acos((6.+asin(pow(fabs(a),b)/t2))/t3) * asin(pow(fabs(b),2.)*1.0/t4) * atan((b*pow(2.,log(fabs(a))))/(t3*t4));
00228 t1 /= cosh(b - 0.7) + 7.*sinh(t1 + 0.8)*tanh(9./a) - 9.;
00229 t1 += pow(fabs(a*4.),b-8.)/cos(a*b*a);
00230
00231 return t1;
00232 }
00233
00234 void testComposite1() {
00235 cc = composite1(ac, bc);
00236 c = composite1(a, b);
00237 comparePCEs(cc, c);
00238 }
00239
00240 protected:
00241
00242
00243 pce_type ac, bc, cc;
00244
00245
00246 double a, b, c;
00247
00248
00249 Sacado::Random urand;
00250
00251
00252 double tol_a, tol_r;
00253
00254 };
00255
00256 #endif // HERMITEUNITTESTS_HPP