You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2013/08/16 20:54:35 UTC
svn commit: r1514847 - in /poi/trunk: src/java/org/apache/poi/ss/formula/atp/
src/java/org/apache/poi/ss/formula/functions/
src/testcases/org/apache/poi/ss/formula/functions/ test-data/spreadsheet/
Author: cedricwalter
Date: Fri Aug 16 18:54:35 2013
New Revision: 1514847
URL: http://svn.apache.org/r1514847
Log:
Bug 55043: patch for missing function QUOTIENT
Added:
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
poi/trunk/test-data/spreadsheet/QuotientFunctionTestCaseData.xls (with props)
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Quotient.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java
poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java?rev=1514847&r1=1514846&r2=1514847&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java Fri Aug 16 18:54:35 2013
@@ -39,8 +39,6 @@ public final class AnalysisToolPak imple
}
}
- ;
-
private final Map<String, FreeRefFunction> _functionsByName = createFunctionsMap();
private AnalysisToolPak() {
@@ -148,7 +146,7 @@ public final class AnalysisToolPak imple
r(m, "PRICE", null);
r(m, "PRICEDISC", null);
r(m, "PRICEMAT", null);
- r(m, "QUOTIENT", null);
+ r(m, "QUOTIENT", Quotient.instance);
r(m, "RANDBETWEEN", RandBetween.instance);
r(m, "RECEIVED", null);
r(m, "RTD", null);
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Quotient.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Quotient.java?rev=1514847&r1=1514846&r2=1514847&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Quotient.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Quotient.java Fri Aug 16 18:54:35 2013
@@ -17,6 +17,7 @@
package org.apache.poi.ss.formula.functions;
+import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.eval.*;
@@ -35,8 +36,12 @@ import org.apache.poi.ss.formula.eval.*;
*
* If either enumerator/denominator is non numeric, QUOTIENT returns the #VALUE! error value.
* If denominator is equals to zero, QUOTIENT returns the #DIV/0! error value.
+ *
+ * @author Cédric Walter
*/
-public class Quotient extends Fixed2ArgFunction {
+public class Quotient extends Fixed2ArgFunction implements FreeRefFunction {
+
+ public static final FreeRefFunction instance = new Quotient();
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval venumerator, ValueEval vedenominator) {
@@ -58,6 +63,13 @@ public class Quotient extends Fixed2ArgF
return ErrorEval.DIV_ZERO;
}
- return new StringEval(String.valueOf((int)(enumerator / denominator)));
+ return new NumberEval((int)(enumerator / denominator));
+ }
+
+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
+ if (args.length != 2) {
+ return ErrorEval.VALUE_INVALID;
+ }
+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java?rev=1514847&r1=1514846&r2=1514847&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java Fri Aug 16 18:54:35 2013
@@ -18,6 +18,7 @@ package org.apache.poi.ss.formula.functi
import junit.framework.TestCase;
import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
@@ -34,8 +35,8 @@ public class TestQuotient extends TestCa
private static void confirmValue(String msg, String numerator, String denominator, String expected) {
ValueEval result = invokeValue(numerator, denominator);
- assertEquals(StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(NumberEval.class, result.getClass());
+ assertEquals(msg, expected, ((NumberEval) result).getStringValue());
}
private static void confirmValueError(String msg, String numerator, String denominator, ErrorEval numError) {
@@ -58,6 +59,6 @@ public class TestQuotient extends TestCa
confirmValueError("numerator is nonnumeric", "ABCD", "", ErrorEval.VALUE_INVALID);
confirmValueError("denominator is nonnumeric", "", "ABCD", ErrorEval.VALUE_INVALID);
- confirmValueError("denominator is nonnumeric", "3.14159", "0", ErrorEval.DIV_ZERO);
+ confirmValueError("dividing by zero", "3.14159", "0", ErrorEval.DIV_ZERO);
}
}
\ No newline at end of file
Added: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java?rev=1514847&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java Fri Aug 16 18:54:35 2013
@@ -0,0 +1,31 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula.functions;
+
+/**
+ * Tests QUOTIENT() as loaded from a test data spreadsheet.<p/>
+ *
+ * @author cedric dot walter @ gmail dot com
+ */
+public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
+
+ @Override
+ protected String getFilename() {
+ return "QuotientFunctionTestCaseData.xls";
+ }
+}
Modified: poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls?rev=1514847&r1=1514846&r2=1514847&view=diff
==============================================================================
Binary files - no diff available.
Added: poi/trunk/test-data/spreadsheet/QuotientFunctionTestCaseData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/QuotientFunctionTestCaseData.xls?rev=1514847&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/spreadsheet/QuotientFunctionTestCaseData.xls
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org