Search in sources :

Example 26 with AreaEval

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

the class TestSumproduct method testAreaWithErrorCell.

public void testAreaWithErrorCell() {
    ValueEval[] aValues = { ErrorEval.REF_INVALID, null };
    AreaEval aeA = EvalFactory.createAreaEval("A1:A2", aValues);
    AreaEval aeB = EvalFactory.createAreaEval("B1:B2", new ValueEval[2]);
    ValueEval[] args = { aeA, aeB };
    assertEquals(ErrorEval.REF_INVALID, invokeSumproduct(args));
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 27 with AreaEval

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

the class TestMatch method testSimpleBoolean.

public void testSimpleBoolean() {
    ValueEval[] values = { BoolEval.FALSE, BoolEval.FALSE, BoolEval.TRUE, BoolEval.TRUE };
    AreaEval ae = EvalFactory.createAreaEval("A1:A4", values);
    // Note String comparisons are case insensitive
    confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
    confirmInt(1, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(BoolEval.TRUE, ae, MATCH_EXACT));
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 28 with AreaEval

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

the class TestMatch method testSimpleWildcardValuesString.

public void testSimpleWildcardValuesString() {
    // Arrange
    ValueEval[] values = { new StringEval("Albert"), new StringEval("Charles"), new StringEval("Ed"), new StringEval("Greg"), new StringEval("Ian") };
    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
    // Note String comparisons are case insensitive
    confirmInt(3, invokeMatch(new StringEval("e*"), ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new StringEval("*d"), ae, MATCH_EXACT));
    confirmInt(1, invokeMatch(new StringEval("Al*"), ae, MATCH_EXACT));
    confirmInt(2, invokeMatch(new StringEval("Char*"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("*eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("G?eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("??eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("G*?eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_EXACT));
    confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_LARGEST_LTE));
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 29 with AreaEval

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

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

AreaEval (org.apache.poi.ss.formula.eval.AreaEval)35 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)29 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)21 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)17 StringEval (org.apache.poi.ss.formula.eval.StringEval)13 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)4 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)4 AssertionFailedError (junit.framework.AssertionFailedError)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)1 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1