}
}
- ;
-
private final Map<String, FreeRefFunction> _functionsByName = createFunctionsMap();
private AnalysisToolPak() {
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);
\r
package org.apache.poi.ss.formula.functions;\r
\r
+import org.apache.poi.ss.formula.OperationEvaluationContext;\r
import org.apache.poi.ss.formula.eval.ValueEval;\r
\r
import org.apache.poi.ss.formula.eval.*;\r
*\r
* If either enumerator/denominator is non numeric, QUOTIENT returns the #VALUE! error value.\r
* If denominator is equals to zero, QUOTIENT returns the #DIV/0! error value.\r
+ *\r
+ * @author Cédric Walter\r
*/\r
-public class Quotient extends Fixed2ArgFunction {\r
+public class Quotient extends Fixed2ArgFunction implements FreeRefFunction {\r
+\r
+ public static final FreeRefFunction instance = new Quotient();\r
\r
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval venumerator, ValueEval vedenominator) {\r
\r
return ErrorEval.DIV_ZERO;\r
}\r
\r
- return new StringEval(String.valueOf((int)(enumerator / denominator)));\r
+ return new NumberEval((int)(enumerator / denominator));\r
+ }\r
+\r
+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {\r
+ if (args.length != 2) {\r
+ return ErrorEval.VALUE_INVALID;\r
+ }\r
+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);\r
}\r
}\r
\r
import junit.framework.TestCase;\r
import org.apache.poi.ss.formula.eval.ErrorEval;\r
+import org.apache.poi.ss.formula.eval.NumberEval;\r
import org.apache.poi.ss.formula.eval.StringEval;\r
import org.apache.poi.ss.formula.eval.ValueEval;\r
\r
\r
private static void confirmValue(String msg, String numerator, String denominator, String expected) {\r
ValueEval result = invokeValue(numerator, denominator);\r
- assertEquals(StringEval.class, result.getClass());\r
- assertEquals(msg, expected, ((StringEval) result).getStringValue());\r
+ assertEquals(NumberEval.class, result.getClass());\r
+ assertEquals(msg, expected, ((NumberEval) result).getStringValue());\r
}\r
\r
private static void confirmValueError(String msg, String numerator, String denominator, ErrorEval numError) {\r
confirmValueError("numerator is nonnumeric", "ABCD", "", ErrorEval.VALUE_INVALID);\r
confirmValueError("denominator is nonnumeric", "", "ABCD", ErrorEval.VALUE_INVALID);\r
\r
- confirmValueError("denominator is nonnumeric", "3.14159", "0", ErrorEval.DIV_ZERO);\r
+ confirmValueError("dividing by zero", "3.14159", "0", ErrorEval.DIV_ZERO);\r
}\r
}
\ No newline at end of file
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss.formula.functions;\r
+\r
+/**\r
+ * Tests QUOTIENT() as loaded from a test data spreadsheet.<p/>\r
+ *\r
+ * @author cedric dot walter @ gmail dot com\r
+ */\r
+public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {\r
+\r
+ @Override\r
+ protected String getFilename() {\r
+ return "QuotientFunctionTestCaseData.xls";\r
+ }\r
+}\r