CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testGenericFunctions.cc

Go to the documentation of this file.
00001 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
00002 #include "CLHEP/GenericFunctions/Sin.hh"
00003 #include "CLHEP/GenericFunctions/Cos.hh"
00004 #include "CLHEP/GenericFunctions/defs.h"
00005 #include <float.h>
00006 #include <assert.h>
00007 #include <cmath>
00008 
00009 int  main(int, char **) {
00010   
00011   using namespace Genfun;
00012 
00013   GENFUNCTION  f = Sin(), g = Cos();
00014   GENPARAMETER p = Parameter("Parameter", 4.0);
00015 
00016   for (double x = 0; x < 100; x++) {
00017     // Test Simple Arithmetic Operations Between Functions
00018     
00019     assert (fabs((f*g) (x) - (sin(x)*cos(x))) <= FLT_EPSILON);
00020     assert (fabs((f+g) (x) - (sin(x)+cos(x))) <= FLT_EPSILON);
00021     assert (fabs((f-g) (x) - (sin(x)-cos(x))) <= FLT_EPSILON);
00022     assert (fabs((f/g) (x) - (sin(x)/cos(x))) <= FLT_EPSILON);
00023     
00024     // Test Simple Arithmetic Operations Between Functions and Parameters
00025     
00026     assert (fabs((p*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
00027     assert (fabs((f*p)(x)- 4.0*sin(x)) <= FLT_EPSILON);
00028     
00029     // Test Simple Arithmetic Operations Between Functions and Constants
00030     
00031     assert (fabs((f*4.0)(x)- 4.0*sin(x)) <= FLT_EPSILON);
00032     assert (fabs((4.0*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
00033     
00034     // Test Function composition
00035     assert (fabs(((f(g))(x)) - sin(cos(x))) <= FLT_EPSILON);
00036     
00037   }
00038   
00039 
00040   // Test Simple Arithmetic Operations Between Parameters 
00041   assert (fabs((p*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
00042 
00043   // Test Simple Arithmetic Operations Between Parameters and Constants
00044   assert (fabs((4*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
00045   assert (fabs((p*4).getValue()- 4.0*4.0) <= FLT_EPSILON);
00046 
00047   // Congratulate the lucky user:
00048   std::cout << "GenericFunctions autotest has passed" << std::endl;
00049   return 0;
00050 }

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7