You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/10/10 13:09:09 UTC

svn commit: r1894109 - /poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java

Author: fanningpj
Date: Sun Oct 10 13:09:09 2021
New Revision: 1894109

URL: http://svn.apache.org/viewvc?rev=1894109&view=rev
Log:
add test case for IRR function

Modified:
    poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java

Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java?rev=1894109&r1=1894108&r2=1894109&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java Sun Oct 10 13:09:09 2021
@@ -17,6 +17,8 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import static org.apache.poi.ss.util.Utils.addRow;
+import static org.apache.poi.ss.util.Utils.assertDouble;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -29,6 +31,8 @@ import org.apache.poi.ss.usermodel.CellT
 import org.apache.poi.ss.usermodel.CellValue;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
+
 /**
  * Tests for {@link Irr}
  */
@@ -119,6 +123,26 @@ final class TestIrr {
         assertEquals(0, failures.length(), "IRR assertions failed");
     }
 
+    @Test
+    void testMicrosoftExample() throws IOException {
+        https://support.microsoft.com/en-us/office/irr-function-64925eaa-9988-495b-b290-3ad0c163c1bc
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet();
+            addRow(sheet, 0, "Data", "Description");
+            addRow(sheet, 1, -70000, "Initial cost of a business");
+            addRow(sheet, 2, 12000, "Net income for the first year");
+            addRow(sheet, 3, 15000, "Net income for the second year");
+            addRow(sheet, 4, 18000, "Net income for the third year");
+            addRow(sheet, 5, 21000, "Net income for the fourth year");
+            addRow(sheet, 6, 26000, "Net income for the fifth year");
+            HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+            HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100);
+            assertDouble(fe, cell, "IRR(A2:A6)", -0.02124484827341093);
+            assertDouble(fe, cell, "IRR(A2:A7)", 0.08663094803653162);
+            assertDouble(fe, cell, "IRR(A2:A4,-0.1)", -0.44350694133474067);
+        }
+    }
+
     private static void assertFormulaResult(CellValue cv, HSSFCell cell){
         double actualValue = cv.getNumberValue();
         double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org