31{
32
33 int numbad = 0;
34 double result;
35
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
68
69 for(int i=0; i<3; ++i ) {
70 eval(exp2[i],numbad,os);
71 }
72
73 return numbad;
74}
double eval(std::string expr, int &numbad, std::ofstream &os)