Search in sources :

Example 6 with I_MatchPredicate

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);
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 7 with I_MatchPredicate

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);
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 8 with I_MatchPredicate

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");
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 9 with I_MatchPredicate

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");
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 10 with I_MatchPredicate

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"));
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AssertionFailedError(junit.framework.AssertionFailedError) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)11 StringEval (org.apache.poi.ss.formula.eval.StringEval)7 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)5 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)4 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)2 AssertionFailedError (junit.framework.AssertionFailedError)1 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)1