use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestCountFuncs method testCountifEmptyStringCriteria.
public void testCountifEmptyStringCriteria() {
I_MatchPredicate mp;
// pred '=' matches blank cell but not empty string
mp = createCriteriaPredicate(new StringEval("="));
confirmPredicate(false, mp, "");
confirmPredicate(true, mp, NULL);
// pred '' matches both blank cell but not empty string
mp = createCriteriaPredicate(new StringEval(""));
confirmPredicate(true, mp, "");
confirmPredicate(true, mp, NULL);
// pred '<>' matches empty string but not blank cell
mp = createCriteriaPredicate(new StringEval("<>"));
confirmPredicate(false, mp, NULL);
confirmPredicate(true, mp, "");
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestCountFuncs method testCountifErrorCriteria.
/**
* the criteria arg value can be an error code (the error does not
* propagate to the COUNTIF result).
*/
public void testCountifErrorCriteria() {
I_MatchPredicate mp;
mp = createCriteriaPredicate(new StringEval("#REF!"));
confirmPredicate(false, mp, 4);
confirmPredicate(false, mp, "#REF!");
confirmPredicate(true, mp, ErrorEval.REF_INVALID);
mp = createCriteriaPredicate(new StringEval("<#VALUE!"));
confirmPredicate(false, mp, 4);
confirmPredicate(false, mp, "#DIV/0!");
confirmPredicate(false, mp, "#REF!");
confirmPredicate(true, mp, ErrorEval.DIV_ZERO);
confirmPredicate(false, mp, ErrorEval.REF_INVALID);
// not quite an error literal, should be treated as plain text
mp = createCriteriaPredicate(new StringEval("<=#REF!a"));
confirmPredicate(false, mp, 4);
confirmPredicate(true, mp, "#DIV/0!");
confirmPredicate(true, mp, "#REF!");
confirmPredicate(false, mp, ErrorEval.DIV_ZERO);
confirmPredicate(false, mp, ErrorEval.REF_INVALID);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestCountFuncs method testCountIf.
public void testCountIf() {
AreaEval range;
ValueEval[] values;
// when criteria is a boolean value
values = new ValueEval[] { new NumberEval(0), // note - does not match boolean TRUE
new StringEval("TRUE"), BoolEval.TRUE, BoolEval.FALSE, BoolEval.TRUE, BlankEval.instance };
range = EvalFactory.createAreaEval("A1:B3", values);
confirmCountIf(2, range, BoolEval.TRUE);
// when criteria is numeric
values = new ValueEval[] { new NumberEval(0), new StringEval("2"), new StringEval("2.001"), new NumberEval(2), new NumberEval(2), BoolEval.TRUE };
range = EvalFactory.createAreaEval("A1:B3", values);
confirmCountIf(3, range, new NumberEval(2));
// note - same results when criteria is a string that parses as the number with the same value
confirmCountIf(3, range, new StringEval("2.00"));
// when criteria is an expression (starting with a comparison operator)
confirmCountIf(2, range, new StringEval(">1"));
// when criteria is an expression (starting with a comparison operator)
confirmCountIf(2, range, new StringEval(">0.5"));
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestWorkdayFunction method testReturnWorkdaysWithDaysTruncated.
@Test
public void testReturnWorkdaysWithDaysTruncated() {
Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 3, 30);
Date expDate = expCal.getTime();
ValueEval[] ve = { new StringEval(STARTING_DATE), new NumberEval(151.99999) };
double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
Date actDate = DateUtil.getJavaDate(numberValue);
assertEquals(expDate, actDate);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestWorkdayFunction method testReturnRetroativeWorkday.
@Test
public void testReturnRetroativeWorkday() {
Calendar expCal = LocaleUtil.getLocaleCalendar(2008, 8, 23);
Date expDate = expCal.getTime();
ValueEval[] ve = { new StringEval(STARTING_DATE), new NumberEval(-5), new StringEval(RETROATIVE_HOLIDAY) };
double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
Date actDate = DateUtil.getJavaDate(numberValue);
assertEquals(expDate, actDate);
}
Aggregations