[Kst] kdeextragear-2/kst/tests

George Staikos staikos at kde.org
Thu Nov 25 01:26:23 CET 2004


CVS commit by staikos: 

- updated eqparser test
- updated test template
- added many tests to histogram, some of which are failing, or I am
  misinterpreting what my histogram should look like


  M +4 -0      testeqparser.cpp   1.15
  M +51 -2     testhistogram.cpp   1.2
  M +14 -0     testtemplate.cpp   1.3


--- kdeextragear-2/kst/tests/testeqparser.cpp  #1.14:1.15
@@ -297,4 +297,8 @@ int main(int argc, char **argv) {
   testParseFail("foo(4, [])");
 
+  exitHelper();
+  if (rc == KstTestSuccess) {
+    printf("All tests passed!\n");
+  }
   return rc;
 }

--- kdeextragear-2/kst/tests/testhistogram.cpp  #1.1:1.2
@@ -17,9 +17,55 @@ int rc = KstTestSuccess;
 
 
+#define doTest(x) testAssert(x, QString("Line %1").arg(__LINE__))
+#define doTestD(x, y) testAssert(x, QString("%1: %2").arg(__LINE__).arg(y))
+
+void testAssert(bool result, const QString& text = "Unknown") {
+  if (!result) {
+    rc = KstTestFailure;
+    printf("Test [%s] failed.\n", text.latin1());
+  }
+}
+
+    
+#define dumpPoints(histogram, n) do { \
+  for (int i = 0; i < n*4; ++i) { \
+    double x, y; \
+    histogram->point(i, x, y); \
+    printf("%.15f, %.15f\n", x, y); \
+  } } while(0)
+
 void doTests() {
   KstVectorPtr vp = KstVector::generateVector(0, 10, 100, "V1");
   KstHistogramPtr h1 = new KstHistogram("H1", vp, 0, 10, 10, KST_HS_NUMBER);
   KST::dataObjectList.append(h1.data());
-  printf("%s\n", h1->propertyString().latin1());;
+  doTest(h1->propertyString() == "Histogram: V1");
+  doTest(!h1->realTimeAutoBin()); // should be false by default
+  h1->setRealTimeAutoBin(true);
+  doTest(h1->realTimeAutoBin());
+  doTest(h1->type() == KST_HISTOGRAM);
+  doTest(h1->nBins() == 10);
+  doTest(h1->vMin() == 0.0);
+  doTest(h1->vMax() == 10.0);
+  doTest(h1->vNumSamples() == 100);
+  int count = 0;
+  for (int i = 1; i < 10*4; i += 3) {
+    double x, y;
+    h1->point(i, x, y);
+    count += int(y);
+  }
+  //dumpPoints(h1, 10);
+  doTest(count == 100); // should account for the whole vector
+  h1->setNBins(11);
+  doTest(h1->nBins() == 11);
+  doTest(h1->vMin() == 0.0);
+  doTest(h1->vMax() == 10.0);
+  doTest(h1->vNumSamples() == 100);
+  for (int i = 1; i < 11*4; i += 3) {
+    double x, y;
+    h1->point(i, x, y);
+    count += int(y);
+  }
+  //dumpPoints(h1, 11);
+  doTest(count == 100); // should still account for the whole vector
 }
 
@@ -28,9 +74,12 @@ int main(int argc, char **argv) {
   atexit(exitHelper);
 
-  KApplication app(argc, argv, "testtemplate", false, false);
+  KApplication app(argc, argv, "testhistogram", false, false);
 
   doTests();
 
   exitHelper(); // before app dies
+  if (rc == KstTestSuccess) {
+    printf("All tests passed!\n");
+  }
   return rc;
 }

--- kdeextragear-2/kst/tests/testtemplate.cpp  #1.2:1.3
@@ -15,4 +15,15 @@ static void exitHelper() {
 int rc = KstTestSuccess;
 
+#define doTest(x) testAssert(x, QString("Line %1").arg(__LINE__))
+#define doTestD(x, y) testAssert(x, QString("%1: %2").arg(__LINE__).arg(y))
+
+void testAssert(bool result, const QString& text = "Unknown") {
+  if (!result) {
+    rc = KstTestFailure;
+    printf("Test [%s] failed.\n", text.latin1());
+  }
+}
+    
+
 void doTests() {
 }
@@ -29,4 +40,7 @@ int main(int argc, char **argv) {
 
   exitHelper(); // need to run it here before kapp goes away in some cases.
+  if (rc == KstTestSuccess) {
+    printf("All tests passed!\n");
+  }
   return rc;
 }





More information about the Kst mailing list