add xmatch test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-06 11:54:38 +00:00
parent 3e3bdd1328
commit 399280c79e
1 changed files with 33 additions and 3 deletions

View File

@ -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;
}
}