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