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/Operations.h"
0003 #include "PhysicsTools/Utilities/interface/Primitive.h"
0004 #include "PhysicsTools/Utilities/interface/FunctionsIO.h"
0005 #include "PhysicsTools/Utilities/interface/Variables.h"
0006 #include "PhysicsTools/Utilities/interface/Fraction.h"
0007 #include "PhysicsTools/Utilities/interface/Simplify.h"
0008 #include <sstream>
0009 #include <iostream>
0010 class testPrimitives : public CppUnit::TestFixture {
0011   CPPUNIT_TEST_SUITE(testPrimitives);
0012   CPPUNIT_TEST(checkAll);
0013   CPPUNIT_TEST_SUITE_END();
0014 
0015 public:
0016   void setUp() {}
0017   void tearDown() {}
0018   void checkAll();
0019 };
0020 
0021 CPPUNIT_TEST_SUITE_REGISTRATION(testPrimitives);
0022 
0023 #define CHECK(EXPR, STRING)                                \
0024   {                                                        \
0025     std::ostringstream str;                                \
0026     str << EXPR;                                           \
0027     std::cerr << #EXPR << " = " << str.str() << std::endl; \
0028     CPPUNIT_ASSERT(str.str() == STRING);                   \
0029   }                                                        \
0030                                                            \
0031   struct __useless_igonreme
0032 
0033 void testPrimitives::checkAll() {
0034   using namespace funct;
0035   X x;
0036   Y y;
0037   Z z;
0038   x = 1, y = 2, z = 3;
0039   funct::Numerical<1> _1;
0040   funct::Numerical<2> _2;
0041   funct::Numerical<3> _3;
0042   funct::Numerical<4> _4;
0043   funct::Numerical<-1> _m1;
0044   funct::Numerical<-2> _m2;
0045   funct::Numerical<-3> _m3;
0046   funct::Numerical<-4> _m4;
0047 
0048   CHECK(primitive<X>(x), "x^2/2");
0049   CHECK(primitive<X>(x ^ _2), "x^3/3");
0050   CHECK(primitive<X>(x ^ _3), "x^4/4");
0051   CHECK(primitive<X>(x ^ _4), "x^5/5");
0052   CHECK(primitive<X>(x ^ _m4), "-( 1/3 )/x^3");
0053   CHECK(primitive<X>(_1 / (x ^ _4)), "-( 1/3 )/x^3");
0054   CHECK(primitive<X>((_1 / x) ^ _4), "-( 1/3 )/x^3");
0055   CHECK(primitive<X>(x ^ (_3 / _4)), "4/7 x^( 7/4 )");
0056   CHECK(primitive<X>(sqrt(x)), "2/3 x^( 3/2 )");
0057   CHECK(primitive<X>(exp(x)), "exp(x)");
0058   CHECK(primitive<X>(log(x)), "x ( log(x) - 1 )");
0059   CHECK(primitive<X>(sgn(x)), "abs(x)");
0060   CHECK(primitive<X>(sin(x)), "-cos(x)");
0061   CHECK(primitive<X>(cos(x)), "sin(x)");
0062   CHECK(primitive<X>(tan(x)), "-log(abs(cos(x)))");
0063   CHECK(primitive<X>(_1 / x), "log(abs(x))");
0064   CHECK((primitive<X>(x ^ _m1)), "log(abs(x))");
0065   CHECK((primitive<X>(_1 / (cos(x) ^ _2))), "tan(x)");
0066   CHECK((primitive<X>(cos(x) ^ _m2)), "tan(x)");
0067   CHECK((primitive<X>(_1 / (sin(x) ^ _2))), "-1/tan(x)");
0068   CHECK((primitive<X>(sin(x) ^ _m2)), "-1/tan(x)");
0069   CHECK(primitive<X>(x * exp(x)), "exp(x) ( x - 1 )");
0070   CHECK(primitive<X>(exp(x) * x), "exp(x) ( x - 1 )");
0071 }