From b628e667768b8a661265272ae38de3a96d8d4c9b Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 29 Mar 2011 14:53:11 +0000 Subject: [PATCH] Correction of bug. --- .../ExprEval/InterpKernelExprParser.cxx | 2 +- src/INTERP_KERNELTest/ExprEvalInterpTest.cxx | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx index 040875469..6e62e30b3 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx @@ -426,7 +426,7 @@ bool ExprParser::tryToInterpALeaf() throw(INTERP_KERNEL::Exception) { std::size_t pos=_expr.find_first_not_of("+-",0,2); std::string minimizedExpr=_expr.substr(pos); - std::size_t pos2=minimizedExpr.find_first_of("+-*/^()",0,7); + std::size_t pos2=minimizedExpr.find_first_of("+-*/^()<>",0,9); if(pos2!=std::string::npos) return false; delete _leaf; diff --git a/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx b/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx index 2bce00618..87bf5ce89 100644 --- a/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx +++ b/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx @@ -384,16 +384,16 @@ void ExprEvalInterpTest::testInterpreterUnit1() void ExprEvalInterpTest::testInterpreter3() { + std::set res; + double input[3]; + double res2[3]; INTERP_KERNEL::ExprParser expr1("2.3+x>5."); expr1.parse(); - std::set res; expr1.getSetOfVars(res); CPPUNIT_ASSERT_EQUAL(1,(int)res.size()); CPPUNIT_ASSERT(*(res.begin())=="x"); expr1.prepareExprEvaluationVec(); - double input[3]; input[0]=0.; - double res2[3]; expr1.evaluateExpr(1,input,res2); CPPUNIT_ASSERT(-std::numeric_limits::max()==res2[0]); input[0]=2.8; @@ -436,6 +436,23 @@ void ExprEvalInterpTest::testInterpreter3() input[0]=2.6; expr3.evaluateExpr(1,input,res2); CPPUNIT_ASSERT_DOUBLES_EQUAL(9.8,res2[0],1e-12); + // + INTERP_KERNEL::ExprParser expr4("if(x>1000,2*x,x/3)"); + expr4.parse(); + res.clear(); + expr4.getSetOfVars(res); + CPPUNIT_ASSERT_EQUAL(1,(int)res.size()); + CPPUNIT_ASSERT(*(res.begin())=="x"); + expr4.prepareExprEvaluationVec(); + input[0]=2.7; + expr4.evaluateExpr(1,input,res2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.9,res2[0],1e-12); + input[0]=999.; + expr4.evaluateExpr(1,input,res2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(333.,res2[0],1e-12); + input[0]=1002.; + expr4.evaluateExpr(1,input,res2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2004.,res2[0],1e-12); } /*! -- 2.39.2