]> source.dussan.org Git - poi.git/commitdiff
[bug-65988] add test case for rate function (failing)
authorPJ Fanning <fanningpj@apache.org>
Thu, 31 Mar 2022 20:08:14 +0000 (20:08 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 31 Mar 2022 20:08:14 +0000 (20:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899452 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/ss/formula/functions/TestRate.java [new file with mode: 0644]

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 (file)
index 0000000..3e7bdbf
--- /dev/null
@@ -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);
+        }
+    }
+}