From ecb8b8240cf8cf1c8a6792f5722b9b3cb84acba7 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sun, 2 Jun 2013 23:25:07 +0000 Subject: [PATCH] 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 --- .../poi/ss/formula/atp/AnalysisToolPak.java | 6 ++---- .../poi/ss/formula/functions/Complex.java | 16 +++++++++++++++- .../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 28215641f..373b65382 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 d37ab70de..0c3981102 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 0000000000000000000000000000000000000000..0d72e7d14dbb16711fb0daa29b65fd050dba6411 GIT binary patch literal 28160 zcmeHQ32YqKdH#2~B$v7<$~rAs8c_!+iKHcxk|j$P#Y3{?PzNL$b`l5jk{pU_Eq9qc zbOaVmw+>p=ZkkArjo4~)I7X2saeUQIQMZ=SAZZKP>0!f(E2K{08YvPqu$!VuYJ2;A z@6GJa%+8K>lOVnJEoOJ-pZC81fB*l#{~hy&{F`sLyz%)bul~Mx(r&4f_w!BC;Gl6{kTlDx z4?cSBcA?jXvpC|hKuTt@z=e3He&@}b7ipu{90aT%2~ zzJHxLLXhKmD&Uurqv?uuS$KsUA?dw>93g4CLXNO3xdNAnXgOexvRZEm#OMfxWP6|- zkt^o7437xLxGWKwqvQyZba$Yn^s(M6=Gb+G93klotnH*vZKo_hj#-{uiI2@H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