[Kst] [Bug 144464] Equation parser doesn't like missing leading zeros

Andrew Walker arwalker at sumusltd.com
Tue May 8 20:38:34 CEST 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=144464         
arwalker sumusltd com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From arwalker sumusltd com  2007-05-08 20:38 -------
SVN commit 662616 by arwalker:

BUG:144464 Checkin Eli's fix for number regexp to 1.5 branch

 M  +83 -2     testeqparser.cpp  


--- branches/work/kst/1.5/kst/tests/testeqparser.cpp #662615:662616
 @ -109,6 +109,58  @
 }
 
 
+bool doTestNotEqual(const char *equation, double x, double result, const double tol = 0.00000000001) {
+  yy_scan_string(equation);
+  int rc = yyparse();
+  if (rc == 0) {
+    vectorsUsed.clear();
+    Equation::Node *eq = static_cast<Equation::Node*>(ParsedEquation);
+    assert(eq);
+    ParsedEquation = 0L;
+    Equation::Context ctx;
+    ctx.sampleCount = 2;
+    ctx.noPoint = NOPOINT;
+    ctx.x = x;
+    ctx.xVector = xVector;
+    if (xVector) {
+      ctx.sampleCount = xVector->length();
+    }
+    Equation::FoldVisitor vis(&ctx, &eq);
+    if (eq->isConst() && !dynamic_cast<Equation::Number*>(eq)) {
+      if (!optimizerFailed) {
+        optimizerFailed = true;
+        ::rc--;
+        printf("Optimizer bug: found an unoptimized const equation.  Optimizing for coverage purposes.\n");
+      }
+      double v = eq->value(&ctx);
+      delete eq;
+      eq = new Equation::Number(v);
+    }
+    KstScalarMap scm;
+    KstStringMap stm;
+    eq->collectObjects(vectorsUsed, scm, stm);
+    eq->update(-1, &ctx);
+    double v = eq->value(&ctx);
+    delete eq;
+    if (fabs(v - result) < tol || (result != result && v != v) || (result == INF && v == INF) || (result == -INF && v == -INF)) {
+      printf("Result: %.16f\n", v);
+      return false;
+    } else {
+      return true;
+    }
+  } else {
+    // Parse error
+    printf("Failures on [%s] -------------------------\n", equation);
+    for (QStringList::ConstIterator i = Equation::errorStack.constBegin(); i != Equation::errorStack.constEnd(); ++i) {
+      printf("%s\n", (*i).latin1());
+    }
+    printf("------------------------------------------\n");
+    delete (Equation::Node*)ParsedEquation;
+    ParsedEquation = 0L;
+    return false;
+  }
+}
+
 void test(const char *equation, double x, double result, const double tol = 0.00000000001) {
   if (!doTest(equation, x, result, tol)) {
     rc--;
 @ -117,6 +169,14  @
 }
 
 
+void testNotEqual(const char *equation, double x, double result, const double tol = 0.00000000001) {
+  if (!doTestNotEqual(equation, x, result, tol)) {
+    rc--;
+    printf("Test of (%s)[%.16f] != %.16f failed.\n", equation, x, result);
+  }
+}
+
+
 void testParseFail(const char *equation) {
   yy_scan_string(equation);
   if (0 == yyparse()) {
 @ -165,6 +225,29  @
   test("1E+1", 0.0, 1E+1);
   test("1E-1", 0.0, 1E-1);
   test("0.2e1", 0.0, 0.2e1);
+  test("01", 0.0, 1);
+  test("0.10", 0.0, 0.1);
+  test("01.", 0.0, 1);
+  test("1.", 0.0, 1.0);
+  test("1.0E5", 0.0, 1.0E5);
+  test("1.0E+5", 0.0, 1.0E+5);
+  test("1.0E-5", 0.0, 1.0E-5);
+  test("1.E5", 0.0, 1.0E5);
+  test("1.E+5", 0.0, 1.0E+5);
+  test("1.E-5", 0.0, 1.0E-5);
+  test("0.1000", 0.0, 0.1000);
+  test(".1000", 0.0, .1000);
+  testNotEqual("E+5", 0.0, 0e5);  // this will actually be 2.7128182846 + 5
+  testNotEqual("E+5", 0.0, 1e5);  // this will actually be 2.7182882846 + 5
+  testNotEqual("E-5", 0.0, 0e-5); // this will actually be 2.7182882846 - 5
+  testNotEqual("E-5", 0.0, 1e-5); // this will actually be 2.7182882846 - 5
+  testParseFail(".");
+  testParseFail("E5");
+  testParseFail(".E5");
+  testParseFail("1E5.0");
+  testParseFail("1E+5.0");
+  testParseFail("1E5.");
+  testParseFail("1E+5.");
 
   // Basics
   test("x", -1.0, -1.0);
 @ -486,8 +569,6  @
   testParseFail("2<=");
   testParseFail("2<=<=2");
   testParseFail("2<==2");
-  testParseFail(".");
-  testParseFail("2.");
   testParseFail(",");
   testParseFail(",2");
   testParseFail("2,"); // Doesn't give a specific error - how to catch this?


More information about the Kst mailing list