aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-06 11:54:38 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-06 11:54:38 +0000
commit399280c79e884a10dbc833a057d32efa4293edcb (patch)
treee21c312b441bcdf717e12eea37763e3d3a62b368 /poi
parent3e3bdd132898d47301dbe8b647aac841df0c8d45 (diff)
downloadpoi-399280c79e884a10dbc833a057d32efa4293edcb.tar.gz
poi-399280c79e884a10dbc833a057d32efa4293edcb.zip
add xmatch test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895618 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/atp/TestXMatchFunction.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXMatchFunction.java b/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXMatchFunction.java
index 559fa22066..a9656e4070 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXMatchFunction.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXMatchFunction.java
@@ -36,7 +36,7 @@ public class TestXMatchFunction {
//https://support.microsoft.com/en-us/office/xmatch-function-d966da31-7a6b-4a13-a1c6-5a33ed6a0312
@Test
void testMicrosoftExample0() throws IOException {
- try (HSSFWorkbook wb = initWorkbook("Grape")) {
+ try (HSSFWorkbook wb = initNumWorkbook("Grape")) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFCell cell = wb.getSheetAt(0).getRow(2).createCell(5);
assertDouble(fe, cell, "XMATCH(E3,C3:C7)", 2);
@@ -46,7 +46,7 @@ public class TestXMatchFunction {
@Test
void testMicrosoftExample1() throws IOException {
- try (HSSFWorkbook wb = initWorkbook("Gra?")) {
+ try (HSSFWorkbook wb = initNumWorkbook("Gra?")) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFCell cell = wb.getSheetAt(0).getRow(2).createCell(5);
assertDouble(fe, cell, "XMATCH(E3,C3:C7,1)", 2);
@@ -57,7 +57,22 @@ public class TestXMatchFunction {
}
}
- private HSSFWorkbook initWorkbook(String lookup) {
+ @Test
+ void testMicrosoftExample2() throws IOException {
+ //the result in this example is correct but the description seems wrong from my testing
+ //the result is based on the position and not a count
+ try (HSSFWorkbook wb = initWorkbook2()) {
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFCell cell = wb.getSheetAt(0).getRow(3).createCell(5);
+ assertDouble(fe, cell, "XMATCH(F2,C3:C9,1)", 4);
+ assertDouble(fe, cell, "XMATCH(F2,C3:C9,-1)", 5);
+ assertError(fe, cell, "XMATCH(F2,C3:C9,2)", FormulaError.NA);
+ assertDouble(fe, cell, "XMATCH(35000,C3:C9,1)", 2);
+ assertDouble(fe, cell, "XMATCH(36000,C3:C9,1)", 1);
+ }
+ }
+
+ private HSSFWorkbook initNumWorkbook(String lookup) {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
addRow(sheet, 0);
@@ -70,4 +85,19 @@ public class TestXMatchFunction {
return wb;
}
+ private HSSFWorkbook initWorkbook2() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet();
+ addRow(sheet, 0);
+ addRow(sheet, 1, null, "Sales Rep", "Total Sales", null, "Bonus", 15000);
+ addRow(sheet, 2, null, "Michael Neipper", 42000);
+ addRow(sheet, 3, null, "Jan Kotas", 35000);
+ addRow(sheet, 4, null, "Nancy Freehafer", 25000);
+ addRow(sheet, 5, null, "Andrew Cencini", 15901);
+ addRow(sheet, 6, null, "Anne Hellung-Larsen", 13801);
+ addRow(sheet, 7, null, "Nancy Freehafer", 12181);
+ addRow(sheet, 8, null, "Mariya Sergienko", 9201);
+ return wb;
+ }
+
}