testToFormulaString(cellC1, "SUM(B8:B10)");
//6 merge area
assertEquals(6, sheet1.getNumMergedRegions());
for (int j = 0; j < 6; ++j) {
CellRangeAddress rng = sheet1.getMergedRegion(j);
switch(j) {
case 0:
assertEquals("E6:F8", rng.formatAsString());
break;
case 1:
assertEquals("E10:F12", rng.formatAsString());
break;
case 2:
assertEquals("G5:H5", rng.formatAsString());
break;
case 3:
assertEquals("E3:F4", rng.formatAsString());
break;
case 4:
assertEquals("I3:J7", rng.formatAsString());
break;
case 5:
assertEquals("E14:F15", rng.formatAsString());
break;
}
}
//remove A4:J6
BookHelper.deleteRange(sheet1, 3, 0, 5, 9, false);
_evaluator.notifySetFormula(cellA1);
_evaluator.notifySetFormula(cellB1);
_evaluator.notifySetFormula(cellC1);
//B4: 5, B5:7, C5: empty, B6: 9, B7: 11, row 8 ~ row 10 empty
Row row4 = sheet1.getRow(3);
row5 = sheet1.getRow(4);
row6 = sheet1.getRow(5);
row7 = sheet1.getRow(6);
row8 = sheet1.getRow(7);
row9 = sheet1.getRow(8);
row10 = sheet1.getRow(9);
assertNull(row5.getCell(2)); //C5 not exist
assertNull(row8.getCell(1));
assertNull(row9.getCell(1));
assertNull(row10.getCell(1));
assertEquals(5, row4.getCell(1).getNumericCellValue(), 0.0000000000000001);
assertEquals(7, row5.getCell(1).getNumericCellValue(), 0.0000000000000001);
assertEquals(9, row6.getCell(1).getNumericCellValue(), 0.0000000000000001);
assertEquals(11, row7.getCell(1).getNumericCellValue(), 0.0000000000000001);
//C1: =SUM(B5:B7)
valueC1 = _evaluator.evaluate(cellC1);
assertEquals(27, valueC1.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueC1.getCellType());
testToFormulaString(cellC1, "SUM(B5:B7)");
//B1: =SUM(B4:B7)
valueB1 = _evaluator.evaluate(cellB1);
assertEquals(32, valueB1.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueB1.getCellType());
testToFormulaString(cellB1, "SUM(B4:B7)");
//A1: =SUM(#REF!)
valueA1 = _evaluator.evaluate(cellA1);
assertEquals(Cell.CELL_TYPE_ERROR, valueA1.getCellType());
testToFormulaString(cellA1, "SUM(#REF!)");
//5 merge area
assertEquals(5, sheet1.getNumMergedRegions()); //G5:H5 unmerged
for (int j = 0; j < 5; ++j) {
CellRangeAddress rng = sheet1.getMergedRegion(j);
switch(j) {
case 0:
assertEquals("E4:F5", rng.formatAsString()); //E6:F8 -> E4:F5
break;
case 1:
assertEquals("E7:F9", rng.formatAsString()); //E10:F12 -> E7:F9
break;
case 2:
assertEquals("E3:F3", rng.formatAsString()); //E3:F4 -> E3:F3
break;
case 3:
assertEquals("I3:J4", rng.formatAsString()); //I3:J7 -> I3:J4
break;
case 4:
assertEquals("E11:F12", rng.formatAsString()); //E14:F15 -> E11:F12
}
}
}