From 782fd29471780a941ae63315cbe7373c352a2121 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sun, 2 Jun 2013 23:25:07 +0000 Subject: added missing tests for Bug 55042: patch for missing function COMPLEX git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1488808 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/formula/atp/AnalysisToolPak.java | 6 ++---- .../org/apache/poi/ss/formula/functions/Complex.java | 16 +++++++++++++++- test-data/spreadsheet/ComplexFunctionTestCaseData.xls | Bin 0 -> 28160 bytes 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 test-data/spreadsheet/ComplexFunctionTestCaseData.xls diff --git a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java index 28215641fd..373b653827 100644 --- a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java @@ -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); diff --git a/src/java/org/apache/poi/ss/formula/functions/Complex.java b/src/java/org/apache/poi/ss/formula/functions/Complex.java index d37ab70def..0c39811028 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Complex.java +++ b/src/java/org/apache/poi/ss/formula/functions/Complex.java @@ -1,5 +1,6 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.*; /** @@ -30,7 +31,9 @@ import org.apache.poi.ss.formula.eval.*; * * @author cedric dot walter @ gmail dot com */ -public class Complex extends Var2or3ArgFunction { +public class Complex extends Var2or3ArgFunction implements FreeRefFunction { + + public static final FreeRefFunction instance = new Complex(); public static final String DEFAULT_SUFFIX = "i"; public static final String SUPPORTED_SUFFIX = "j"; @@ -116,4 +119,15 @@ public class Complex extends Var2or3ArgFunction { return (number == Math.floor(number)) && !Double.isInfinite(number); } + @Override + public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { + if (args.length == 2) { + return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); + } + if (args.length == 3) { + return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1], args[2]); + } + + return ErrorEval.VALUE_INVALID; + } } diff --git a/test-data/spreadsheet/ComplexFunctionTestCaseData.xls b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls new file mode 100644 index 0000000000..0d72e7d14d Binary files /dev/null and b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls differ -- cgit v1.2.3