Bug 55043: patch for missing function QUOTIENT
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1514847 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67f198e752
commit
72d3a7d2a3
@ -39,8 +39,6 @@ public final class AnalysisToolPak implements UDFFinder {
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private final Map<String, FreeRefFunction> _functionsByName = createFunctionsMap();
|
||||
|
||||
private AnalysisToolPak() {
|
||||
@ -148,7 +146,7 @@ public final class AnalysisToolPak implements UDFFinder {
|
||||
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);
|
||||
|
@ -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 Fixed2ArgFunction {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package org.apache.poi.ss.formula.functions;
|
||||
|
||||
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 TestCase {
|
||||
|
||||
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 TestCase {
|
||||
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);
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
Binary file not shown.
BIN
test-data/spreadsheet/QuotientFunctionTestCaseData.xls
Normal file
BIN
test-data/spreadsheet/QuotientFunctionTestCaseData.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user