]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Correction of bug.
authorageay <ageay>
Tue, 29 Mar 2011 14:53:11 +0000 (14:53 +0000)
committerageay <ageay>
Tue, 29 Mar 2011 14:53:11 +0000 (14:53 +0000)
src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx
src/INTERP_KERNELTest/ExprEvalInterpTest.cxx

index 0408754697183ca51b730ad546e967b71fb35b9d..6e62e30b32ef1215372477626a2ebdd57997e969 100644 (file)
@@ -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;
index 2bce00618ddd78940d6ba45bd22b6028fd62e4a7..87bf5ce89cf2a94dc05f4d9b6715768ffbcf531e 100644 (file)
@@ -384,16 +384,16 @@ void ExprEvalInterpTest::testInterpreterUnit1()
 
 void ExprEvalInterpTest::testInterpreter3()
 {
+  std::set<std::string> res;
+  double input[3];
+  double res2[3];
   INTERP_KERNEL::ExprParser expr1("2.3+x>5.");
   expr1.parse();
-  std::set<std::string> 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<double>::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);
 }
 
 /*!