You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2012/02/28 12:53:25 UTC

svn commit: r1294595 - in /poi/trunk: src/documentation/content/xdocs/ src/documentation/content/xdocs/spreadsheet/ src/java/org/apache/poi/ss/formula/functions/ src/testcases/org/apache/poi/ss/formula/eval/ src/testcases/org/apache/poi/ss/formula/func...

Author: yegor
Date: Tue Feb 28 11:53:25 2012
New Revision: 1294595

URL: http://svn.apache.org/viewvc?rev=1294595&view=rev
Log:
bugzilla 52057 - updated formula test framework to be aware of recently added Functions

Modified:
    poi/trunk/src/documentation/content/xdocs/spreadsheet/eval-devguide.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/NumericFunction.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java
    poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls
    poi/trunk/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx

Modified: poi/trunk/src/documentation/content/xdocs/spreadsheet/eval-devguide.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/spreadsheet/eval-devguide.xml?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/spreadsheet/eval-devguide.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/spreadsheet/eval-devguide.xml Tue Feb 28 11:53:25 2012
@@ -206,6 +206,23 @@
             </p>
         </section>
 
+	<section><title>Testing Framework</title>
+	<p>Automated testing of the implemented Function is easy.
+	The source code for this is in the file: o.a.p.h.record.formula.GenericFormulaTestCase.java
+	This class has a reference to the test xls file (not /a/ test xls, /the/ test xls :)
+	which may need to be changed for your environment. Once you do that, in the test xls,
+	locate the entry for the function that you have implemented and enter different tests 
+	in a cell in the FORMULA row. Then copy the "value of" the formula that you entered in the
+	cell just below it (this is easily done in excel as: 
+	[copy the formula cell] > [go to cell below] > Edit > Paste Special > Values > "ok").
+	You can enter multiple such formulas and paste their values in the cell below and the
+	test framework will automatically test if the formula evaluation matches the expected
+	value (Again, hard to put in words, so if you will, please take time to quickly look
+	at the code and the currently entered tests in the patch attachment "FormulaEvalTestData.xls" 
+	file).
+	</p>	
+	</section>
+
         <anchor id="appendixA"/>
         <section>
            <title>Appendix A</title>
@@ -354,4 +371,4 @@
             </source>
         </section>
 	</body>
-</document>
\ No newline at end of file
+</document>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Feb 28 11:53:25 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">52057 - updated formula test framework to be aware of recently added Functions </action>
            <action dev="poi-developers" type="add">52574 - support setting header / footer page margins in HSSF </action>
            <action dev="poi-developers" type="add">52583 - fixed WorkbookUtil#createSafeSheetName to escape colon </action>
            <action dev="poi-developers" type="add">51710 - fixed reading shared formulas in XSSF </action>

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/NumericFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/NumericFunction.java?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/NumericFunction.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/NumericFunction.java Tue Feb 28 11:53:25 2012
@@ -331,7 +331,8 @@ public abstract class NumericFunction im
 				double d0 = singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
 				double d1 = singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
 				double multi = Math.pow(10d,d1);
-				result = Math.floor(d0 * multi) / multi;
+				if(d0 < 0) result = -Math.floor(-d0 * multi) / multi;
+                else result = Math.floor(d0 * multi) / multi;
 				checkValue(result);
 			}catch (EvaluationException e) {
 				return e.getErrorEval();

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java Tue Feb 28 11:53:25 2012
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.formula.eval;
 
 import java.io.PrintStream;
+import java.util.Collection;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
@@ -31,6 +32,8 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellValue;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Tests formulas and operators as loaded from a test data spreadsheet.<p/>
@@ -43,6 +46,7 @@ import org.apache.poi.ss.usermodel.Sheet
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  */
 public final class TestFormulasFromSpreadsheet extends TestCase {
+    private static final POILogger logger = POILogFactory.getLogger(TestFormulasFromSpreadsheet.class);
 
 	private static final class Result {
 		public static final int SOME_EVALUATIONS_FAILED = -1;
@@ -167,9 +171,7 @@ public final class TestFormulasFromSprea
 			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
 			throw new AssertionFailedError(msg);
 		}
-		if(false) { // normally no output for successful tests
-			System.out.println(getClass().getName() + ": " + successMsg);
-		}
+        logger.log(POILogger.INFO, getClass().getName() + ": " + successMsg);
 	}
 
 	/**
@@ -179,6 +181,7 @@ public final class TestFormulasFromSprea
 	 */
 	private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
 		HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);
+        Collection<String> funcs = FunctionEval.getSupportedFunctionNames();
 
 		int rowIndex = startRowIndex;
 		while (true) {
@@ -208,6 +211,12 @@ public final class TestFormulasFromSprea
 					default:
 						throw new RuntimeException("unexpected result");
 					case Result.NO_EVALUATIONS_FOUND: // do nothing
+                        String uname = targetFunctionName.toUpperCase();
+                        if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
+                                funcs.contains(uname)) {
+                            logger.log(POILogger.WARN, uname + ": function is supported but missing test data");
+                        }
+                        break;
 				}
 			}
 			rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION;

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java Tue Feb 28 11:53:25 2012
@@ -56,4 +56,11 @@ public final class TestTrunc extends Abs
 		ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
 		assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
 	}
+
+    public void testNegative() {
+        ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) };
+        @SuppressWarnings("static-access")
+        ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
+        assertEquals("TRUNC", (new NumberEval(-8)).getNumberValue(), ((NumberEval)result).getNumberValue());
+    }
 }

Modified: poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/trunk/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx?rev=1294595&r1=1294594&r2=1294595&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org