CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testGenericFunctions.cc
Go to the documentation of this file.
5#include <float.h>
6#include <assert.h>
7#include <cmath>
8
9int main(int, char **) {
10
11 using namespace Genfun;
12
13 GENFUNCTION f = Sin(), g = Cos();
14 GENPARAMETER p = Parameter("Parameter", 4.0);
15
16 for (double x = 0; x < 100; x++) {
17 // Test Simple Arithmetic Operations Between Functions
18
19 assert (fabs((f*g) (x) - (sin(x)*cos(x))) <= FLT_EPSILON);
20 assert (fabs((f+g) (x) - (sin(x)+cos(x))) <= FLT_EPSILON);
21 assert (fabs((f-g) (x) - (sin(x)-cos(x))) <= FLT_EPSILON);
22 assert (fabs((f/g) (x) - (sin(x)/cos(x))) <= FLT_EPSILON);
23
24 // Test Simple Arithmetic Operations Between Functions and Parameters
25
26 assert (fabs((p*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
27 assert (fabs((f*p)(x)- 4.0*sin(x)) <= FLT_EPSILON);
28
29 // Test Simple Arithmetic Operations Between Functions and Constants
30
31 assert (fabs((f*4.0)(x)- 4.0*sin(x)) <= FLT_EPSILON);
32 assert (fabs((4.0*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
33
34 // Test Function composition
35 assert (fabs(((f(g))(x)) - sin(cos(x))) <= FLT_EPSILON);
36
37 }
38
39
40 // Test Simple Arithmetic Operations Between Parameters
41 assert (fabs((p*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
42
43 // Test Simple Arithmetic Operations Between Parameters and Constants
44 assert (fabs((4*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
45 assert (fabs((p*4).getValue()- 4.0*4.0) <= FLT_EPSILON);
46
47 // Congratulate the lucky user:
48 std::cout << "GenericFunctions autotest has passed" << std::endl;
49 return 0;
50}
void f(void g())
int main()