]> source.dussan.org Git - poi.git/commitdiff
Bug 55037: patch for missing function DELTA
authorCédric Walter <cedricwalter@apache.org>
Mon, 7 Oct 2013 09:42:38 +0000 (09:42 +0000)
committerCédric Walter <cedricwalter@apache.org>
Mon, 7 Oct 2013 09:42:38 +0000 (09:42 +0000)
 Add missing TestDeltaFunctionsFromSpreadsheet and register Delta in AnalysisToolPak

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1529809 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
src/java/org/apache/poi/ss/formula/functions/Delta.java
src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java [new file with mode: 0644]
test-data/spreadsheet/DeltaFunctionTestCaseData.xls [new file with mode: 0644]

index 551ff754747e0b6104fc1e56509788d8b13cdaad..b866c61bf3c3ca4e0a17b93b581bb04f2b2fdd9d 100644 (file)
@@ -91,7 +91,7 @@ public final class AnalysisToolPak implements UDFFinder {
         r(m, "DEC2BIN", null);
         r(m, "DEC2HEX", null);
         r(m, "DEC2OCT", null);
-        r(m, "DELTA", null);
+        r(m, "DELTA", Delta.instance);
         r(m, "DISC", null);
         r(m, "DOLLARDE", null);
         r(m, "DOLLARFR", null);
index 8488189aa545f87421e85bdda94f27b1214249f0..2f1bd88dfc732cf475d9c29f9773c66dcf5a43f3 100644 (file)
@@ -17,6 +17,7 @@
 \r
 package org.apache.poi.ss.formula.functions;\r
 \r
+import org.apache.poi.ss.formula.OperationEvaluationContext;\r
 import org.apache.poi.ss.formula.eval.*;\r
 \r
 import java.math.BigDecimal;\r
@@ -37,7 +38,9 @@ import java.math.BigDecimal;
  *\r
  * @author cedric dot walter @ gmail dot com\r
  */\r
-public final class Delta extends Fixed2ArgFunction {\r
+public final class Delta extends Fixed2ArgFunction implements FreeRefFunction {\r
+\r
+    public static final FreeRefFunction instance = new Delta();\r
 \r
     private final static NumberEval ONE = new NumberEval(1);\r
     private final static NumberEval ZERO = new NumberEval(0);\r
@@ -72,4 +75,11 @@ public final class Delta extends Fixed2ArgFunction {
         return result == 0 ? ONE : ZERO;\r
     }\r
 \r
+    public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {\r
+         if (args.length == 2) {\r
+            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);\r
+        }\r
+\r
+        return ErrorEval.VALUE_INVALID;\r
+    }\r
 }
\ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
new file mode 100644 (file)
index 0000000..47bea21
--- /dev/null
@@ -0,0 +1,13 @@
+package org.apache.poi.ss.formula.functions;\r
+\r
+/**\r
+* Tests DELTA() as loaded from a test data spreadsheet.<p/>\r
+*\r
+* @author cedric dot walter @ gmail dot com\r
+*/\r
+public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {\r
+\r
+    protected String getFilename() {\r
+        return "DeltaFunctionTestCaseData.xls";\r
+    }\r
+}\r
diff --git a/test-data/spreadsheet/DeltaFunctionTestCaseData.xls b/test-data/spreadsheet/DeltaFunctionTestCaseData.xls
new file mode 100644 (file)
index 0000000..e66e96c
Binary files /dev/null and b/test-data/spreadsheet/DeltaFunctionTestCaseData.xls differ