use of org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate 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.functions.CountUtils.I_MatchPredicate in project poi by apache.
the class TestCountFuncs method testCountifAreaCriteria.
/**
* the criteria arg is mostly handled by {@link OperandResolver#getSingleValue(org.apache.poi.ss.formula.eval.ValueEval, int, int)}}
*/
public void testCountifAreaCriteria() {
// anything but column A
int srcColIx = 2;
ValueEval v0 = new NumberEval(2.0);
ValueEval v1 = new StringEval("abc");
ValueEval v2 = ErrorEval.DIV_ZERO;
AreaEval ev = EvalFactory.createAreaEval("A10:A12", new ValueEval[] { v0, v1, v2 });
I_MatchPredicate mp;
mp = Countif.createCriteriaPredicate(ev, 9, srcColIx);
confirmPredicate(true, mp, srcColIx);
confirmPredicate(false, mp, "abc");
confirmPredicate(false, mp, ErrorEval.DIV_ZERO);
mp = Countif.createCriteriaPredicate(ev, 10, srcColIx);
confirmPredicate(false, mp, srcColIx);
confirmPredicate(true, mp, "abc");
confirmPredicate(false, mp, ErrorEval.DIV_ZERO);
mp = Countif.createCriteriaPredicate(ev, 11, srcColIx);
confirmPredicate(false, mp, srcColIx);
confirmPredicate(false, mp, "abc");
confirmPredicate(true, mp, ErrorEval.DIV_ZERO);
confirmPredicate(false, mp, ErrorEval.VALUE_INVALID);
// tricky: indexing outside of A10:A12
// even this #VALUE! error gets used by COUNTIF as valid criteria
mp = Countif.createCriteriaPredicate(ev, 12, srcColIx);
confirmPredicate(false, mp, srcColIx);
confirmPredicate(false, mp, "abc");
confirmPredicate(false, mp, ErrorEval.DIV_ZERO);
confirmPredicate(true, mp, ErrorEval.VALUE_INVALID);
}
use of org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate in project poi by apache.
the class TestCountFuncs method testNotQuiteWildCards.
public void testNotQuiteWildCards() {
I_MatchPredicate mp;
// make sure special reg-ex chars are treated like normal chars
mp = createCriteriaPredicate(new StringEval("a.b"));
confirmPredicate(false, mp, "aab");
confirmPredicate(true, mp, "a.b");
mp = createCriteriaPredicate(new StringEval("a~b"));
confirmPredicate(false, mp, "ab");
confirmPredicate(false, mp, "axb");
confirmPredicate(false, mp, "a~~b");
confirmPredicate(true, mp, "a~b");
mp = createCriteriaPredicate(new StringEval(">a*b"));
confirmPredicate(false, mp, "a(b");
confirmPredicate(true, mp, "aab");
confirmPredicate(false, mp, "a*a");
confirmPredicate(true, mp, "a*c");
}
use of org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate in project poi by apache.
the class TestCountFuncs method testCountifComparisons.
public void testCountifComparisons() {
I_MatchPredicate mp;
mp = createCriteriaPredicate(new StringEval(">5"));
confirmPredicate(false, mp, 4);
confirmPredicate(false, mp, 5);
confirmPredicate(true, mp, 6);
mp = createCriteriaPredicate(new StringEval("<=5"));
confirmPredicate(true, mp, 4);
confirmPredicate(true, mp, 5);
confirmPredicate(false, mp, 6);
confirmPredicate(false, mp, "4.9");
confirmPredicate(false, mp, "4.9t");
confirmPredicate(false, mp, "5.1");
confirmPredicate(false, mp, NULL);
mp = createCriteriaPredicate(new StringEval("=abc"));
confirmPredicate(true, mp, "abc");
mp = createCriteriaPredicate(new StringEval("=42"));
confirmPredicate(false, mp, 41);
confirmPredicate(true, mp, 42);
confirmPredicate(true, mp, "42");
mp = createCriteriaPredicate(new StringEval(">abc"));
confirmPredicate(false, mp, 4);
confirmPredicate(false, mp, "abc");
confirmPredicate(true, mp, "abd");
mp = createCriteriaPredicate(new StringEval(">4t3"));
confirmPredicate(false, mp, 4);
confirmPredicate(false, mp, 500);
confirmPredicate(true, mp, "500");
confirmPredicate(true, mp, "4t4");
}
use of org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate in project poi by apache.
the class TestCountFuncs method testCriteriaPredicateNe_Bug46647.
public void testCriteriaPredicateNe_Bug46647() {
I_MatchPredicate mp = Countif.createCriteriaPredicate(new StringEval("<>aa"), 0, 0);
assertNotNull(mp);
// this should not match the criteria '<>aa'
StringEval seA = new StringEval("aa");
// this should match
StringEval seB = new StringEval("bb");
if (mp.matches(seA) && !mp.matches(seB)) {
throw new AssertionFailedError("Identified bug 46647");
}
assertFalse(mp.matches(seA));
assertTrue(mp.matches(seB));
// general tests for not-equal (<>) operator
AreaEval range;
ValueEval[] values;
values = new ValueEval[] { new StringEval("aa"), new StringEval("def"), new StringEval("aa"), new StringEval("ghi"), new StringEval("aa"), new StringEval("aa") };
range = EvalFactory.createAreaEval("A1:A6", values);
confirmCountIf(2, range, new StringEval("<>aa"));
values = new ValueEval[] { new StringEval("ab"), new StringEval("aabb"), // match
new StringEval("aa"), new StringEval("abb"), new StringEval("aab"), // match
new StringEval("ba") };
range = EvalFactory.createAreaEval("A1:A6", values);
confirmCountIf(2, range, new StringEval("<>a*b"));
values = new ValueEval[] { new NumberEval(222), new NumberEval(222), new NumberEval(111), new StringEval("aa"), new StringEval("111") };
range = EvalFactory.createAreaEval("A1:A5", values);
confirmCountIf(4, range, new StringEval("<>111"));
}
Aggregations