[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kspread/tests
From:       Ariya Hidayat <ariya () kde ! org>
Date:       2004-11-03 12:26:54
Message-ID: 20041103122654.24E1A16C91 () office ! kde ! org
[Download RAW message or body]

CVS commit by ariya: 

tester for checking formula evaluation
only trivial cases are there, more will follow 


  M +52 -0     formula_tester.cc   1.3
  M +12 -0     formula_tester.h   1.2
  M +1 -0      testrunner.cc   1.7


--- koffice/kspread/tests/formula_tester.cc  #1.2:1.3
@@ -22,6 +22,8 @@
 
 #include <formula.h>
+#include <kspread_value.h>
 
 #define CHECK_PARSE(x,y)  checkParse(__FILE__,__LINE__,#x,x,y)
+#define CHECK_EVAL(x,y)  checkEval(__FILE__,__LINE__,#x,x,y)
 
 using namespace KSpread;
@@ -162,2 +164,52 @@ void FormulaParserTester::run()
   CHECK_PARSE( "+1.23E", QString::null );  
 }
+
+FormulaEvalTester::FormulaEvalTester(): Tester()
+{
+}
+
+QString FormulaEvalTester::name()
+{
+  return QString("Formula (Eval)");
+}
+
+void FormulaEvalTester::checkEval( const char *file, int line, const char* msg, 
+  const QString& formula, const KSpreadValue& expected )
+{
+  testCount++;
+  
+  Formula f;
+  QString expr = formula;
+  expr.prepend( '=' );
+  f.setExpression( expr );
+  KSpreadValue result = f.eval();
+
+  if( !result.equal( expected ) )
+  {
+    QString message;
+    QTextStream ts( &message, IO_WriteOnly );
+    ts << msg;
+    ts << " Result: " << result;
+    ts << " Expected: " << expected;
+    fail( file, line, message );
+  }
+}
+
+
+void FormulaEvalTester::run()
+{
+  testCount = 0;
+  errorList.clear();
+  
+  // simple constants
+  CHECK_EVAL( "0", KSpreadValue(0) );
+  CHECK_EVAL( "1", KSpreadValue(1) );
+  CHECK_EVAL( "-1", KSpreadValue(-1) );
+  CHECK_EVAL( "3.14e7", KSpreadValue(3.14e7) );
+  CHECK_EVAL( "3.14-e7", KSpreadValue(3.14e-7) );
+  
+  
+  // simple binary operation  
+  CHECK_EVAL( "0+0", KSpreadValue(0) );
+  CHECK_EVAL( "1+1", KSpreadValue(2) );
+}

--- koffice/kspread/tests/formula_tester.h  #1.1:1.2
@@ -25,4 +25,6 @@
 #include "tester.h"
 
+#include <kspread_value.h>
+
 namespace KSpread
 {
@@ -38,4 +40,14 @@ private:
 };
 
+class FormulaEvalTester: public Tester
+{
+public:
+  FormulaEvalTester();
+  virtual QString name();
+  virtual void run();
+private:
+  void checkEval( const char *file, int line, const char* msg, const QString&, const KSpreadValue& );
+};
+
 }; // namespace KSpread
 

--- koffice/kspread/tests/testrunner.cc  #1.6:1.7
@@ -82,4 +82,5 @@ TestRunner::TestRunner():
   addTester( new ValueTester() );
   addTester( new FormulaParserTester() );
+  addTester( new FormulaEvalTester() );
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic