Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:33

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "PhysicsTools/Utilities/interface/Polynomial.h"
0003 #include <cmath>
0004 
0005 class testPolynomial : public CppUnit::TestFixture {
0006   CPPUNIT_TEST_SUITE(testPolynomial);
0007   CPPUNIT_TEST(checkAll);
0008   CPPUNIT_TEST_SUITE_END();
0009 
0010 public:
0011   void setUp() {}
0012   void tearDown() {}
0013   void checkAll();
0014 };
0015 
0016 CPPUNIT_TEST_SUITE_REGISTRATION(testPolynomial);
0017 
0018 void testPolynomial::checkAll() {
0019   double c[] = {1, 2, 3, 4, 5};
0020   double x = 10;
0021   const double epsilon = 1.e-5;
0022   funct::Polynomial<0> poly0(c);
0023   CPPUNIT_ASSERT(fabs(poly0(x) - c[0]) < epsilon);
0024   funct::Polynomial<1> poly1(c);
0025   CPPUNIT_ASSERT(fabs(poly1(x) - (c[0] + x * c[1])) < epsilon);
0026   funct::Polynomial<2> poly2(c);
0027   CPPUNIT_ASSERT(fabs(poly2(x) - (c[0] + x * c[1] + x * x * c[2])) < epsilon);
0028   funct::Polynomial<3> poly3(c);
0029   CPPUNIT_ASSERT(fabs(poly3(x) - (c[0] + x * c[1] + x * x * c[2] + x * x * x * c[3])) < epsilon);
0030 }