Lines 45-51
Link Here
|
45 |
public final class TestCountFuncs extends TestCase { |
45 |
public final class TestCountFuncs extends TestCase { |
46 |
|
46 |
|
47 |
private static final String NULL = null; |
47 |
private static final String NULL = null; |
|
|
48 |
|
49 |
public void testCountBlank() { |
48 |
|
50 |
|
|
|
51 |
AreaEval range; |
52 |
ValueEval[] values; |
53 |
|
54 |
values = new ValueEval[] { |
55 |
new NumberEval(0), |
56 |
new StringEval(""), // note - does not match blank |
57 |
BoolEval.TRUE, |
58 |
BoolEval.FALSE, |
59 |
ErrorEval.DIV_ZERO, |
60 |
BlankEval.INSTANCE, |
61 |
}; |
62 |
range = EvalFactory.createAreaEval("A1:B3", values); |
63 |
confirmCountBlank(1, range); |
64 |
|
65 |
values = new ValueEval[] { |
66 |
new NumberEval(0), |
67 |
new StringEval(""), // note - does not match blank |
68 |
BlankEval.INSTANCE, |
69 |
BoolEval.FALSE, |
70 |
BoolEval.TRUE, |
71 |
BlankEval.INSTANCE, |
72 |
}; |
73 |
range = EvalFactory.createAreaEval("A1:B3", values); |
74 |
confirmCountBlank(2, range); |
75 |
} |
76 |
|
49 |
public void testCountA() { |
77 |
public void testCountA() { |
50 |
|
78 |
|
51 |
ValueEval[] args; |
79 |
ValueEval[] args; |
Lines 196-201
Link Here
|
196 |
double result = NumericFunctionInvoker.invoke(new Countif(), args); |
224 |
double result = NumericFunctionInvoker.invoke(new Countif(), args); |
197 |
assertEquals(expected, result, 0); |
225 |
assertEquals(expected, result, 0); |
198 |
} |
226 |
} |
|
|
227 |
private static void confirmCountBlank(int expected, AreaEval range) { |
228 |
|
229 |
ValueEval[] args = { range }; |
230 |
double result = NumericFunctionInvoker.invoke(new Countblank(), args); |
231 |
assertEquals(expected, result, 0); |
232 |
} |
199 |
|
233 |
|
200 |
private static I_MatchPredicate createCriteriaPredicate(ValueEval ev) { |
234 |
private static I_MatchPredicate createCriteriaPredicate(ValueEval ev) { |
201 |
return Countif.createCriteriaPredicate(ev, 0, 0); |
235 |
return Countif.createCriteriaPredicate(ev, 0, 0); |
Lines 418-421
Link Here
|
418 |
throw new AssertionFailedError(failureCount + " countif evaluations failed. See stderr for more details"); |
452 |
throw new AssertionFailedError(failureCount + " countif evaluations failed. See stderr for more details"); |
419 |
} |
453 |
} |
420 |
} |
454 |
} |
|
|
455 |
|
456 |
public void testCounBlankFromSpreadsheet() { |
457 |
final String FILE_NAME = "countblankExamples.xls"; |
458 |
final int START_ROW_IX = 1; |
459 |
final int COL_IX_ACTUAL = 3; |
460 |
final int COL_IX_EXPECTED = 4; |
461 |
|
462 |
int failureCount = 0; |
463 |
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(FILE_NAME); |
464 |
HSSFSheet sheet = wb.getSheetAt(0); |
465 |
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); |
466 |
int maxRow = sheet.getLastRowNum(); |
467 |
for (int rowIx=START_ROW_IX; rowIx<maxRow; rowIx++) { |
468 |
HSSFRow row = sheet.getRow(rowIx); |
469 |
if(row == null) { |
470 |
continue; |
471 |
} |
472 |
HSSFCell cell = row.getCell(COL_IX_ACTUAL); |
473 |
CellValue cv = fe.evaluate(cell); |
474 |
double actualValue = cv.getNumberValue(); |
475 |
double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue(); |
476 |
if (actualValue != expectedValue) { |
477 |
System.err.println("Problem with test case on row " + (rowIx+1) + " " |
478 |
+ "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") "); |
479 |
failureCount++; |
480 |
} |
481 |
} |
482 |
|
483 |
if (failureCount > 0) { |
484 |
throw new AssertionFailedError(failureCount + " countblank evaluations failed. See stderr for more details"); |
485 |
} |
486 |
} |
421 |
} |
487 |
} |