Browse Source

Bug 55043: patch for missing function QUOTIENT

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1514847 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_10_BETA2
Cédric Walter 10 years ago
parent
commit
f75f0ec612

+ 1
- 3
src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java View File

@@ -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);

+ 14
- 2
src/java/org/apache/poi/ss/formula/functions/Quotient.java View File

@@ -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]);
}
}

+ 4
- 3
src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java View File

@@ -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);
}
}

+ 31
- 0
src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java View File

@@ -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";
}
}

BIN
test-data/spreadsheet/FormulaEvalTestData.xls View File


BIN
test-data/spreadsheet/QuotientFunctionTestCaseData.xls View File


Loading…
Cancel
Save