]> source.dussan.org Git - poi.git/commitdiff
added missing tests for Bug 55042: patch for missing function COMPLEX
authorYegor Kozlov <yegor@apache.org>
Sun, 2 Jun 2013 23:25:07 +0000 (23:25 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 2 Jun 2013 23:25:07 +0000 (23:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1488808 13f79535-47bb-0310-9956-ffa450edef68

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

index 28215641fdb632b1e9a1e45e306b71b8a7ca26f2..373b653827e133fc8a169afac320d18742cacd2f 100644 (file)
@@ -15,9 +15,7 @@ import org.apache.poi.ss.formula.eval.NotImplementedException;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.function.FunctionMetadata;
 import org.apache.poi.ss.formula.function.FunctionMetadataRegistry;
-import org.apache.poi.ss.formula.functions.EDate;
-import org.apache.poi.ss.formula.functions.FreeRefFunction;
-import org.apache.poi.ss.formula.functions.Sumifs;
+import org.apache.poi.ss.formula.functions.*;
 import org.apache.poi.ss.formula.udf.UDFFinder;
 
 import java.util.*;
@@ -74,7 +72,7 @@ public final class AnalysisToolPak implements UDFFinder {
         r(m, "BIN2DEC", null);
         r(m, "BIN2HEX", null);
         r(m, "BIN2OCT", null);
-        r(m, "COMPLEX", null);
+        r(m, "COMPLEX", Complex.instance);
         r(m, "CONVERT", null);
         r(m, "COUNTIFS", null);
         r(m, "COUPDAYBS", null);
index d37ab70def217f6fd99b286cbd27b99a8f00a2a0..0c398110282bd76322889cd29a67228b9ba954e1 100644 (file)
@@ -1,5 +1,6 @@
 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
 /**\r
@@ -30,7 +31,9 @@ import org.apache.poi.ss.formula.eval.*;
  *\r
  * @author cedric dot walter @ gmail dot com\r
  */\r
-public class Complex extends Var2or3ArgFunction {\r
+public class Complex extends Var2or3ArgFunction implements FreeRefFunction {\r
+\r
+    public static final FreeRefFunction instance = new Complex();\r
 \r
     public static final String DEFAULT_SUFFIX = "i";\r
     public static final String SUPPORTED_SUFFIX = "j";\r
@@ -116,4 +119,15 @@ public class Complex extends Var2or3ArgFunction {
         return (number == Math.floor(number)) && !Double.isInfinite(number);\r
     }\r
 \r
+    @Override\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
+        if (args.length == 3) {\r
+            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1], args[2]);\r
+        }\r
+\r
+        return ErrorEval.VALUE_INVALID;\r
+    }\r
 }\r
diff --git a/test-data/spreadsheet/ComplexFunctionTestCaseData.xls b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls
new file mode 100644 (file)
index 0000000..0d72e7d
Binary files /dev/null and b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls differ