aboutsummaryrefslogtreecommitdiffstats
path: root/poi/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-10 13:09:09 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-10 13:09:09 +0000
commit8ed95f7970c584668536fd9132e4ac61ef19fef8 (patch)
tree29e188adc546d811984f39e54b58e12e562d8259 /poi/src
parent5bcf3c3d734a0034bc2970838cc80cb9e01ec485 (diff)
downloadpoi-8ed95f7970c584668536fd9132e4ac61ef19fef8.tar.gz
poi-8ed95f7970c584668536fd9132e4ac61ef19fef8.zip
add test case for IRR function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894109 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src')
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java
index 6764ebdc2b..289fc826c9 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIrr.java
@@ -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.CellType;
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