[Kst] kdeextragear-2/kst/tests

George Staikos staikos at kde.org
Mon Nov 22 19:05:19 CET 2004


CVS commit by staikos: 

Now have coverage of entire scanner and parser (minus error paths, multiple
buffers, and restarting in the generated code), and >70% coverage of the
interpreter.  Only interpolation and plugin calling are untested.


  M +57 -4     testeqparser.cpp   1.6


--- kdeextragear-2/kst/tests/testeqparser.cpp  #1.5:1.6
@@ -4,5 +4,7 @@
  */
 
+#include <assert.h>
 #include <enodes.h>
+#include <kstdatacollection.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -25,9 +27,13 @@ double INF = 1.0/0.0;
 bool optimizerFailed = false;
 
+KstVectorList vectorsUsed;
+
 bool doTest(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;
@@ -45,4 +51,5 @@ bool doTest(const char *equation, double
                         eq = new Equation::Number(v);
                 }
+                eq->collectVectors(vectorsUsed);
                 eq->update(-1, &ctx);
                 double v = eq->value(&ctx);
@@ -70,6 +77,23 @@ void test(const char *equation, double x
 
 
+void testParseFail(const char *equation) {
+        yy_scan_string(equation);
+        if (0 == yyparse()) {
+                printf("Test of (%s) parsing passed, but should have failed.\n", equation);
+                //exit(-1);
+        }
+}
+
+
+static void exitHelper() {
+        vectorsUsed.clear();
+        KST::vectorList.clear();
+        KST::scalarList.clear();
+}
+
+
 int main() {
-        //test("", 1.0, 0.0);  Should it pass?  Currently gives parse error
+        atexit(exitHelper);
+        test("", 1.0, 0.0);  // TODO: Should it pass?  Currently gives parse error
 
         // Base cases
@@ -228,11 +252,40 @@ int main() {
 
         // Hmmm?
-        test("-1|257", 0.0, 257.0);  // What should be correct?
-        test("257|-1", 0.0, 257.0);  // What should be correct?
+        test("-1|257", 0.0, 257.0);  // TODO: What should be correct?
+        test("257|-1", 0.0, 257.0);  // TODO: What should be correct?
 
-        // TODO: Vectors, Scalars
+        // Scalars
+        new KstScalar("test1", 1.0, true);
+        new KstScalar("test2", 0.0, true);
+        new KstScalar("test3", -1.0, true);
+        new KstScalar("test4", NOPOINT, true);
+        new KstScalar("test5", INF, true);
+        new KstScalar("test6", -INF, true);
+
+        test("[test1]", 0.0, 1.0);
+        test("[test4]", 0.0, NOPOINT);
+        test("[test4] - [test4]", 0.0, NOPOINT);
+        test("[test4] - [test5]", 0.0, NOPOINT);
+        test("[test4]*[test5]", 0.0, NOPOINT);
+        test("[sdf]", 0.0, NOPOINT);
+
+        // Vectors
+        KstVector::generateVector(0, 1.0, 10, "V1");
+        KstVector::generateVector(1.0, 2.0, 10, "V2");
+        KstVector::generateVector(0, 1.0, 2, "V3");
+        KstVector::generateVector(-1.0, 1.0, 1000, "V4");
+        test("[V2] - [V1]", 0.0, 1.0);
 
         // TODO: Plugins
 
+        // Errors:
+        printf("-- Ignore any ERROR: after this line. --------------------\n");
+        testParseFail("[]");
+        testParseFail("foo(, 3)");
+        testParseFail("foo(3,)"); // FAILS
+        testParseFail("foo(3,,5)"); // FAILS
+        testParseFail("foo([])");
+        testParseFail("foo(4, [])");
+
         return 0;
 }





More information about the Kst mailing list