diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-02-25 18:04:56 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-02-25 18:04:56 +0000 |
commit | ba252f20b5aa30d5a992d79a8fd0932a5086a981 (patch) | |
tree | c65e61f50e55d9d60f1d5503ea717c3f952308ba | |
parent | 114eca28a86aa0aa16f56fb4a43b2d7337628517 (diff) | |
download | poi-ba252f20b5aa30d5a992d79a8fd0932a5086a981.tar.gz poi-ba252f20b5aa30d5a992d79a8fd0932a5086a981.zip |
add index test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898420 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndex.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndex.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndex.java index 5ffc8c8323..1d1eed6498 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndex.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestIndex.java @@ -17,12 +17,18 @@ package org.apache.poi.ss.formula.functions; +import static org.apache.poi.ss.util.Utils.assertDouble; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.util.Arrays; import org.apache.poi.hssf.HSSFTestDataSamples; +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.apache.poi.ss.formula.WorkbookEvaluator; import org.apache.poi.ss.formula.eval.AreaEval; @@ -317,4 +323,33 @@ final class TestIndex { assertEquals(7.0, fe.evaluate(c1).getNumberValue(), 0); } + + @Test + void testMicrosoftExample2() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + //https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); + assertDouble(fe, cell, "INDEX({1,2;3,4},0,2)", 2.0); + } + } + + @Test + void testMicrosoftExample2ArrayFunction() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + //https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row0 = sheet.createRow(0); + HSSFCell cell0 = row0.createCell(0); + HSSFRow row1 = sheet.createRow(1); + HSSFCell cell1 = row1.createCell(0); + sheet.setArrayFormula("INDEX({1,2;3,4},0,2)", new CellRangeAddress(0, 1, 0, 0)); + fe.evaluateAll(); + assertEquals(2.0, cell0.getNumericCellValue()); + assertEquals(4.0, cell1.getNumericCellValue()); + } + } } |