Search in sources :

Example 46 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval 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 47 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval 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 48 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.

the class TestCountFuncs method confirmPredicate.

private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, String value) {
    ValueEval ev = value == null ? BlankEval.instance : new StringEval(value);
    assertEquals(expectedResult, matchPredicate.matches(ev));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 49 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval 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 50 with StringEval

use of org.apache.poi.ss.formula.eval.StringEval 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

StringEval (org.apache.poi.ss.formula.eval.StringEval)58 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)48 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)29 Test (org.junit.Test)18 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)13 Calendar (java.util.Calendar)10 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)10 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)9 Date (java.util.Date)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)7 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 BigDecimal (java.math.BigDecimal)1 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1