Search in sources :

Example 16 with AreaEval

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

the class TestIndex method testMissingArg.

/**
	 * Tests expressions like "INDEX(A1:C1,,2)".<br/>
	 * This problem was found while fixing bug 47048 and is observable up to svn r773441.
	 */
public void testMissingArg() {
    ValueEval[] values = { new NumberEval(25.0), new NumberEval(26.0), new NumberEval(28.0) };
    AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
    ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2) };
    ValueEval actualResult;
    try {
        actualResult = FUNC_INST.evaluate(args, -1, -1);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) {
            throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg");
        }
        throw e;
    }
    // result should be an area eval "B10:B10"
    AreaEval ae = confirmAreaEval("B10:B10", actualResult);
    actualResult = ae.getValue(0, 0);
    assertEquals(NumberEval.class, actualResult.getClass());
    assertEquals(26.0, ((NumberEval) actualResult).getNumberValue(), 0.0);
}
Also used : 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)

Example 17 with AreaEval

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

the class TestMatch method testSimpleNumber.

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

Example 18 with AreaEval

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

the class TestIndex method confirmAreaEval.

/**
	 * @param areaRefString in Excel notation e.g. 'D2:E97'
	 * @param dValues array of evaluated values for the area reference
	 * @param rowNum 1-based
	 * @param colNum 1-based, pass -1 to signify argument not present
	 */
private static void confirmAreaEval(String areaRefString, double[] dValues, int rowNum, int colNum, double expectedResult) {
    ValueEval[] values = new ValueEval[dValues.length];
    for (int i = 0; i < values.length; i++) {
        values[i] = new NumberEval(dValues[i]);
    }
    AreaEval arg0 = EvalFactory.createAreaEval(areaRefString, values);
    ValueEval[] args;
    if (colNum > 0) {
        args = new ValueEval[] { arg0, new NumberEval(rowNum), new NumberEval(colNum) };
    } else {
        args = new ValueEval[] { arg0, new NumberEval(rowNum) };
    }
    double actual = invokeAndDereference(args);
    assertEquals(expectedResult, actual, 0D);
}
Also used : 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 19 with AreaEval

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

the class TestIndex method confirmAreaEval.

/**
	 * Confirms that the result is an area ref with the specified coordinates
	 * @return <tt>ve</tt> cast to {@link AreaEval} if it is valid
	 */
private static AreaEval confirmAreaEval(String refText, ValueEval ve) {
    CellRangeAddress cra = CellRangeAddress.valueOf(refText);
    assertTrue(ve instanceof AreaEval);
    AreaEval ae = (AreaEval) ve;
    assertEquals(cra.getFirstRow(), ae.getFirstRow());
    assertEquals(cra.getFirstColumn(), ae.getFirstColumn());
    assertEquals(cra.getLastRow(), ae.getLastRow());
    assertEquals(cra.getLastColumn(), ae.getLastColumn());
    return ae;
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 20 with AreaEval

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

the class TestPercentile method invokePercentile.

private static ValueEval invokePercentile(ValueEval[] args, ValueEval percentile) {
    AreaEval aeA = EvalFactory.createAreaEval("A1:A" + args.length, args);
    ValueEval[] args2 = { aeA, percentile };
    return AggregateFunction.PERCENTILE.evaluate(args2, -1, -1);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

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