From b1c98d3999acf1eba498d9eded44b4f9b1b5e007 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 31 Mar 2022 20:08:14 +0000 Subject: [PATCH] [bug-65988] add test case for rate function (failing) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899452 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/functions/TestRate.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 poi/src/test/java/org/apache/poi/ss/formula/functions/TestRate.java diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRate.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRate.java new file mode 100644 index 0000000000..3e7bdbfe35 --- /dev/null +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestRate.java @@ -0,0 +1,65 @@ +/* + * ==================================================================== + * 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; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.apache.poi.ss.util.Utils.addRow; +import static org.apache.poi.ss.util.Utils.assertDouble; + +/** + * Test cases for RATE() + */ +final class TestRate { + + @Test + void testMicrosoftExample1() throws Exception { + //https://support.microsoft.com/en-us/office/rate-function-9f665657-4a7e-4bb7-a030-83fc59e748ce + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + addRow(sheet, 0, "Data", "Description"); + addRow(sheet, 1, 4, "Years of loan"); + addRow(sheet, 2, -200, "Monthly payment"); + addRow(sheet, 3, 8000, "Amount of the loan"); + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFCell cell = sheet.getRow(0).createCell(100); + assertDouble(fe, cell, "RATE(A2*12, A3, A4)", 0.007701472, 0.000001); + assertDouble(fe, cell, "RATE(A2*12, A3, A4)*12", 0.09241767, 0.000001); + } + } + + @Disabled("test fails - see related issue") + @Test + void testBug65988() throws Exception { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFCell cell = row.createCell(0); + assertDouble(fe, cell, "RATE(360.0,6.56,-2000.0)", 0.0009480170844060, 0.000001); + } + } +} -- 2.39.5