CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testBug90848.cc File Reference
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <limits>
#include "CLHEP/Evaluator/Evaluator.h"

Go to the source code of this file.

Classes

class  MyEvaluator
 
struct  Test
 

Functions

int main ()
 

Variables

Test tests []
 

Function Documentation

◆ main()

int main ( )

Definition at line 55 of file testBug90848.cc.

55 {
57
58 e.setVariable("x",1.0);
59 e.setVariable("y",2.0);
60 e.setVariable("z",3.0);
61//printf("x=1.0 y=2.0 z=3.0\n");
62 int err=0;
63 for(unsigned i=0; i<sizeof(tests)/sizeof(Test); ++i) {
64 double v=e.evaluate(tests[i].expr);
65 if(std::isnan(v) || std::fabs(v-tests[i].value1) > 1E-12 || !e.isOK()) {
66 printf("%s = %.6f should be %.6f\n",tests[i].expr,
67 e.evaluate(tests[i].expr),tests[i].value1);
68 err = 1;
69 }
70 }
71
72 e.setVariable("x",10.0);
73 e.setVariable("y",-20.0);
74 e.setVariable("z",-30.0);
75//printf("x=10.0 y=-20.0 z=-30.0\n");
76 for(unsigned i=0; i<sizeof(tests)/sizeof(Test); ++i) {
77 double v=e.evaluate(tests[i].expr);
78 if(std::isnan(v) || std::fabs(v-tests[i].value2) > 1E-12 || !e.isOK()) {
79 printf("%s = %.6f should be %.6f\n",tests[i].expr,
80 e.evaluate(tests[i].expr),tests[i].value2);
81 err = 1;
82 }
83 }
84
85 double v=e.evaluate("unknown(0.0)");
86 if(!std::isnan(v) || e.isOK()) {
87 printf("%s succeeded\n","unknown(0.0)");
88 err=1;
89 }
90
91 v = e.evaluate("unknown+0.0");
92 if(!std::isnan(v) || e.isOK()) {
93 printf("%s succeeded\n","unknown+0.0");
94 err=1;
95 }
96
97 exit(err);
98}
void setVariable(const char *name, double value)
Definition: Evaluator.cc:713
double evaluate(const char *e)
Definition: testBug90848.cc:14
#define exit(x)
const char * expr
Definition: testBug90848.cc:22
double value1
Definition: testBug90848.cc:23
double value2
Definition: testBug90848.cc:24
Test tests[]
Definition: testBug90848.cc:27

Variable Documentation

◆ tests

Test tests[]
Initial value:
= {
{ "x", 1.0, 10.0},
{ "y", 2.0, -20.0},
{ "z", 3.0, -30.0},
{ "x+y", 3.0, -10.0},
{ "-z", -3.0, 30.0},
{ "0-z", -3.0, 30.0},
{ "0 - -z", 3.0, -30.0},
{ "10/-x", -10.0, -1.0},
{ "exp(-y)*exp(y)", 1.0, 1.0},
{ "exp(-y^2)*exp(y^2)", 1.0, 1.0},
{ "-5*x", -5.0, -50.0},
{ "5+-x", 4.0, -5.0},
{ "5+(-x)", 4.0, -5.0},
{ "5*-x", -5.0, -50.0},
{ "5*(-x)", -5.0, -50.0},
{ "-z^2", -9.0, -900.0},
{ "0-z^2", -9.0, -900.0},
{ "exp(-0.2*z^2)*exp(0.2*z^2)", 1.0, 1.0},
{ "exp(0.2*-z^2)*exp(0.2*z^2)", 1.0, 1.0},
{ "exp(-z^2*0.2)*exp(0.2*z^2)", 1.0, 1.0},
{ "exp(0.2*-(z^2))*exp(0.2*z^2)", 1.0, 1.0},
{ "exp(-(z^2)*0.2)*exp(0.2*z^2)", 1.0, 1.0},
{ "exp(-0.2*z)*exp(0.2*z)", 1.0, 1.0},
{ "exp(0.2*-z)*exp(0.2*z)", 1.0, 1.0},
{ "exp(-z*0.2)*exp(0.2*z)", 1.0, 1.0},
}

Definition at line 27 of file testBug90848.cc.

Referenced by main().