Search in sources :

Example 21 with AreaEval

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

the class TestMatch method testHeterogeneous.

public void testHeterogeneous() {
    ValueEval[] values = { new NumberEval(4), BoolEval.FALSE, new NumberEval(5), new StringEval("Albert"), BoolEval.FALSE, BoolEval.TRUE, new NumberEval(10), new StringEval("Charles"), new StringEval("Ed"), new NumberEval(10), new NumberEval(25), BoolEval.TRUE, new StringEval("Ed") };
    AreaEval ae = EvalFactory.createAreaEval("A1:A13", values);
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));
    confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
    confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
    confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
    //wildcard values
    confirmInt(8, invokeMatch(new StringEval("CHAR*"), ae, MATCH_EXACT));
    confirmInt(8, invokeMatch(new StringEval("*CHARLES"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("ED*"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("*ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
    confirmInt(9, invokeMatch(new StringEval("ED*"), ae, MATCH_EXACT));
    confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
    confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
    confirmInt(12, invokeMatch(BoolEval.TRUE, 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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 22 with AreaEval

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

the class TestMatch method testMatchArgTypeArea.

/**
	 * Ensures that the match_type argument can be an <tt>AreaEval</tt>.<br/>
	 * Bugzilla 44421
	 */
public void testMatchArgTypeArea() {
    ValueEval[] values = { new NumberEval(4), new NumberEval(5), new NumberEval(10), new NumberEval(10), new NumberEval(25) };
    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
    AreaEval matchAE = EvalFactory.createAreaEval("C1:C1", new ValueEval[] { MATCH_LARGEST_LTE });
    try {
        confirmInt(4, invokeMatch(new NumberEval(10), ae, matchAE));
    } catch (RuntimeException e) {
        if (e.getMessage().startsWith("Unexpected match_type type")) {
            // identified bug 44421
            fail(e.getMessage());
        }
        // some other error ??
        throw e;
    }
}
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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 23 with AreaEval

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

the class TestMatch method testReversedNumber.

public void testReversedNumber() {
    ValueEval[] values = { new NumberEval(25), new NumberEval(10), new NumberEval(10), new NumberEval(10), new NumberEval(4) };
    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
    confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_SMALLEST_GTE));
    confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new NumberEval(9), ae, MATCH_SMALLEST_GTE));
    confirmInt(1, invokeMatch(new NumberEval(20), ae, MATCH_SMALLEST_GTE));
    confirmInt(5, invokeMatch(new NumberEval(3), ae, MATCH_SMALLEST_GTE));
    assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(20), ae, MATCH_EXACT));
    assertEquals(ErrorEval.NA, invokeMatch(new NumberEval(26), ae, MATCH_SMALLEST_GTE));
}
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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 24 with AreaEval

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

the class TestMatch method testSimpleString.

public void testSimpleString() {
    // 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("Ed"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("eD"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new StringEval("ed"), ae, MATCH_EXACT));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
}
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 25 with AreaEval

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

the class TestSumproduct method testOneByOneArea.

/**
	 * For scalar products, the terms may be 1x1 area refs
	 */
public void testOneByOneArea() {
    AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7) });
    ValueEval[] args = { ae, new NumberEval(2) };
    ValueEval result = invokeSumproduct(args);
    confirmDouble(14D, result);
}
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) 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