From: ageay Date: Thu, 10 Feb 2011 15:22:15 +0000 (+0000) Subject: Bug correction when some blank in expr. X-Git-Tag: V6_main_FINAL~1079 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e46d9b0351b25431f720c42c41840e8a86c004f;p=tools%2Fmedcoupling.git Bug correction when some blank in expr. --- diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx index 2d8055ffe..2aa5ead3b 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx @@ -124,12 +124,14 @@ LeafExprVar::~LeafExprVar() ExprParser::ExprParser(const char *expr, ExprParser *father):_father(father),_is_parsed(false),_leaf(0),_is_parsing_ok(false),_expr(expr) { + _expr=deleteWhiteSpaces(_expr); } //! For \b NOT null terminated strings coming from FORTRAN. ExprParser::ExprParser(const char *expr, int lgth, ExprParser *father):_father(father),_is_parsed(false),_leaf(0),_is_parsing_ok(false) { _expr=buildStringFromFortran(expr,lgth); + _expr=deleteWhiteSpaces(_expr); } ExprParser::~ExprParser() diff --git a/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx b/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx index 96032f6a3..2bce00618 100644 --- a/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx +++ b/src/INTERP_KERNELTest/ExprEvalInterpTest.cxx @@ -437,3 +437,21 @@ void ExprEvalInterpTest::testInterpreter3() expr3.evaluateExpr(1,input,res2); CPPUNIT_ASSERT_DOUBLES_EQUAL(9.8,res2[0],1e-12); } + +/*! + * Bug detected by Marc concerning expressions with blanks. + */ +void ExprEvalInterpTest::testInterpreter4() +{ + INTERP_KERNEL::ExprParser expr("2*x + 1"); + double vals[3]={0.1,0.2,0.3}; + std::vector varsV(3); + varsV[0] = "x"; + varsV[1] = "y"; + varsV[2] = "z"; + expr.parse(); + expr.prepareExprEvaluation(varsV); + double result; + expr.evaluateExpr(1,vals, &result); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.2,result,1e-12); +} diff --git a/src/INTERP_KERNELTest/ExprEvalInterpTest.hxx b/src/INTERP_KERNELTest/ExprEvalInterpTest.hxx index 2730af59a..b43050cb1 100644 --- a/src/INTERP_KERNELTest/ExprEvalInterpTest.hxx +++ b/src/INTERP_KERNELTest/ExprEvalInterpTest.hxx @@ -37,6 +37,7 @@ namespace INTERP_TEST CPPUNIT_TEST( testInterpreterUnit0 ); CPPUNIT_TEST( testInterpreterUnit1 ); CPPUNIT_TEST( testInterpreter3 ); + CPPUNIT_TEST( testInterpreter4 ); CPPUNIT_TEST_SUITE_END(); public: void setUp() { } @@ -48,6 +49,7 @@ namespace INTERP_TEST void testInterpreter1(); void testInterpreter2(); void testInterpreter3(); + void testInterpreter4(); void testInterpreterUnit0(); void testInterpreterUnit1(); };