]> source.dussan.org Git - poi.git/commitdiff
bugzilla 52057 - updated formula test framework to be aware of recently added Functions
authorYegor Kozlov <yegor@apache.org>
Tue, 28 Feb 2012 11:53:25 +0000 (11:53 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 28 Feb 2012 11:53:25 +0000 (11:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1294595 13f79535-47bb-0310-9956-ffa450edef68

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

index 551b2f1333f840aabdffe2ba761cef609d9fa294..d59b8034b56307fef41aa49bd2ed2a139c1a6589 100644 (file)
             </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>
             </source>
         </section>
        </body>
-</document>
\ No newline at end of file
+</document>
index 7bb0f71feb5db928ca7f27aa77bcb4675e253adc..3e6792d0786bf9f3a7a5b9b29cf5d16acce31e38 100644 (file)
@@ -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>
index 623cf65db368a0f8671e6d2a4805321618d263d2..38d8006537e3dcf13c14cd7230892be0d329be91 100644 (file)
@@ -331,7 +331,8 @@ public abstract class NumericFunction implements Function {
                                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();
index fd0771fdc8034e0fb9a3193216540d58ed8f69e2..fbbe0efdbd506cd7a4b00a5a8c00e9095f239a19 100644 (file)
@@ -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 TestFormulasFromSpreadsheet extends TestCase {
                        + _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 TestFormulasFromSpreadsheet extends TestCase {
         */
        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 TestFormulasFromSpreadsheet extends TestCase {
                                        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;
index c3ed45974526c1b07041986d8ef49b2a97ce0f39..55360b96c433f24826dc48c8ae270bbafb5e619d 100644 (file)
@@ -56,4 +56,11 @@ public final class TestTrunc extends AbstractNumericTestCase {
                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());
+    }
 }
index 919bf867e2a7ade7e3a061156ca52160abca0c39..4aa144093bae07e5603760937bd4fd19362219cc 100644 (file)
Binary files a/test-data/spreadsheet/FormulaEvalTestData.xls and b/test-data/spreadsheet/FormulaEvalTestData.xls differ
index 8e491a54edfbb7f0836ef06e56cab95eb3146d3d..848ea3f012a02429b0ecdd0e87e9e4c8baa9e972 100644 (file)
Binary files a/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx and b/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx differ