Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 02A9C10512 for ; Fri, 16 Aug 2013 18:55:01 +0000 (UTC) Received: (qmail 33086 invoked by uid 500); 16 Aug 2013 18:55:00 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 33046 invoked by uid 500); 16 Aug 2013 18:54:58 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 33035 invoked by uid 99); 16 Aug 2013 18:54:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Aug 2013 18:54:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Aug 2013 18:54:55 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CEE2523888E7; Fri, 16 Aug 2013 18:54:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: 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/ Date: Fri, 16 Aug 2013 18:54:35 -0000 To: commits@poi.apache.org From: cedricwalter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130816185435.CEE2523888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 _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.

+ * + * @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