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

testBug66214.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------------
2 //
3 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
4 //
5 // This is a test for bug report 66214 in the Evaluator class.
6 //
7 #include <iostream>
8 #include <fstream>
10 
11 double eval( std::string expr, int& numbad, std::ofstream& os)
12 {
13  static HepTool::Evaluator *ev=0;
14  if(ev == 0) ev = new HepTool::Evaluator();
15  ev->setStdMath(); // set standard constants and functions
16  ev->setSystemOfUnits(); // set SI units
17 
18  double v = ev->evaluate(expr.data());
19 
20  os << "CALC> " << expr << ": ";
21  if(ev->status() != HepTool::Evaluator::OK) {
22  os << ev->error_name() << std::endl;
23  ++numbad;
24  } else {
25  os << v << std::endl;
26  }
27  return v;
28 }
29 
30 int main()
31 {
32 
33  int numbad = 0;
34  double result;
35  // many of these expressions fail in releases prior to 2.0.4.7
36  std::string exp[43] = { " +1", " -1", "1 + 1", "1 + -1","1 + (-1)",
37  "1 + +1","1 + (+1)", "1 * -1","1 * (-1)", "-1 * 1",
38  "10^-1", "10^(-1)", "9*4", "9 * -4","9 * (-4)",
39  "4*---2","4*(---2)","4*(-(--2))","4*(--(-2))","4*(-(-(-2)))",
40  "4*--2", "4*(--2)", "4*(-(-2))", "-5^2", "9*4+2",
41  "231/-11","231/-11+10","231/-11/3","(231/-11)+10",
42  "100/5^2","100/+5^2","100/-5^2", "9*4+30", "9*4+-30",
43  "100/(5^2)","100/(+5^2)","100/(-5^2)", "100/(-5)^2", "100/((-5)^2)",
44  "-9*4+30","9*-4+30","9*(-4)+30","(9*-4)+30" };
45  double res[43] = { 1., -1., 2., 0., 0.,
46  2., 2., -1., -1., -1.,
47  0.1, 0.1, 36., -36., -36.,
48  -8., -8., -8., -8., -8.,
49  8., 8., 8., -25., 38.,
50  -21., -11., -7., -11.,
51  4., 4., -4., 66., 6.,
52  4., 4., -4., 4., 4.,
53  -6., -6., -6., -6. };
54  std::string exp2[3] = { "sin(45*deg)", "sin(45*pi/-180)", "232/22" };
55 
56  std::ofstream os("testBug66214.cout");
57 
58  for(int i=0; i<43; ++i ) {
59  result=eval(exp[i],numbad,os);
60  if( result != res[i] ) {
61  ++numbad;
62  os << "ERROR: expected " << res[i] << " got " << result << std::endl;
63  os << std::endl;
64  }
65  }
66 
67  // inspect these by hand
68  // return values: 0.707107, -0.707107, 10.5455
69  for(int i=0; i<3; ++i ) {
70  eval(exp2[i],numbad,os);
71  }
72 
73  return numbad;
74 }
HepTool::Evaluator
Definition: CLHEP/Evaluator/Evaluator.h:26
main
int main()
Definition: testBug66214.cc:30
HepTool::Evaluator::status
int status() const
Definition: Evaluator.cc:632
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
result
this formatted text is the function s string result this method sends the formatted string s to the ostream destination specified when the logger was instantiated as its result
Definition: ZMthrow_event_sequence.txt:148
HepTool::Evaluator::error_name
std::string error_name() const
Definition: Evaluator.cc:651
eval
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition: testBug66214.cc:11
HepTool::Evaluator::setSystemOfUnits
void setSystemOfUnits(double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)
Definition: setSystemOfUnits.cc:10
HepTool::Evaluator::OK
@ OK
Definition: CLHEP/Evaluator/Evaluator.h:40
i
long i
Definition: JamesRandomSeeding.txt:27
HepTool::Evaluator::setStdMath
void setStdMath()
Definition: setStdMath.cc:31
HepTool::Evaluator::evaluate
double evaluate(const char *expression)
Definition: Evaluator.cc:612
Evaluator.h