* Two COUNTIF examples taken from
* http://office.microsoft.com/en-us/excel-help/countif-function-HP010069840.aspx?CTT=5&origin=HA010277524
*/
public void testCountifExamples() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("countifExamples.xls");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFSheet sheet1 = wb.getSheet("MSDN Example 1");
for (int rowIx=7; rowIx<=12; rowIx++) {
HSSFRow row = sheet1.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
assertEquals(
"Problem with a formula at " + new CellReference(cellA).formatAsString()
+ ": " + cellA.getCellFormula() + " :"
+ "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ",
expectedValue, actualValue, 0.0001);
}
HSSFSheet sheet2 = wb.getSheet("MSDN Example 2");
for (int rowIx=9; rowIx<=14; rowIx++) {
HSSFRow row = sheet2.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
assertEquals(
"Problem with a formula at " +