Search in sources :

Example 6 with AreaEval

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

the class TestSubtotal method confirmSubtotal.

private static void confirmSubtotal(int function, double expected) {
    ValueEval[] values = new ValueEval[TEST_VALUES0.length];
    for (int i = 0; i < TEST_VALUES0.length; i++) {
        values[i] = new NumberEval(TEST_VALUES0[i]);
    }
    AreaEval arg1 = EvalFactory.createAreaEval("C1:D5", values);
    ValueEval[] args = { new NumberEval(function), arg1 };
    ValueEval result = new Subtotal().evaluate(args, 0, 0);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
}
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 7 with AreaEval

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

the class TestSumif method testCriteriaArgRange.

/**
	 * test for bug observed near svn r882931
	 */
public void testCriteriaArgRange() {
    ValueEval[] arg0values = new ValueEval[] { _50, _60, _50, _50, _50, _30 };
    ValueEval[] arg1values = new ValueEval[] { _30, _40, _50, _60 };
    AreaEval arg0;
    AreaEval arg1;
    ValueEval ve;
    arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
    // single row range
    arg1 = EvalFactory.createAreaEval("A2:D2", arg1values);
    // invoking from cell C1
    ve = invokeSumif(0, 2, arg0, arg1);
    if (ve instanceof NumberEval) {
        NumberEval ne = (NumberEval) ve;
        if (ne.getNumberValue() == 30.0) {
            throw new AssertionFailedError("identified error in SUMIF - criteria arg not evaluated properly");
        }
    }
    confirmDouble(200, ve);
    arg0 = EvalFactory.createAreaEval("C1:D3", arg0values);
    // single column range
    arg1 = EvalFactory.createAreaEval("B1:B4", arg1values);
    // invoking from cell A4
    ve = invokeSumif(3, 0, arg0, arg1);
    confirmDouble(60, ve);
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) 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 8 with AreaEval

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

the class TestSumif method testBasic.

public void testBasic() {
    ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 };
    ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 };
    AreaEval arg0;
    AreaEval arg2;
    arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
    arg2 = EvalFactory.createAreaEval("D1:E3", arg2values);
    confirm(60.0, arg0, new NumberEval(30.0));
    confirm(70.0, arg0, new NumberEval(30.0), arg2);
    confirm(100.0, arg0, new StringEval(">45"));
    confirm(100.0, arg0, new StringEval(">=45"));
    confirm(100.0, arg0, new StringEval(">=50.0"));
    confirm(140.0, arg0, new StringEval("<45"));
    confirm(140.0, arg0, new StringEval("<=45"));
    confirm(140.0, arg0, new StringEval("<=40.0"));
    confirm(160.0, arg0, new StringEval("<>40.0"));
    confirm(80.0, arg0, new StringEval("=40.0"));
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) 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 9 with AreaEval

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

the class TestSumproduct method testMismatchAreaDimensions.

public void testMismatchAreaDimensions() {
    AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]);
    AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]);
    ValueEval[] args;
    args = new ValueEval[] { aeA, aeB };
    assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
    args = new ValueEval[] { aeA, new NumberEval(5) };
    assertEquals(ErrorEval.VALUE_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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 10 with AreaEval

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

the class TestSumproduct method testAreaSimple.

public void testAreaSimple() {
    ValueEval[] aValues = { new NumberEval(2), new NumberEval(4), new NumberEval(5) };
    ValueEval[] bValues = { new NumberEval(3), new NumberEval(6), new NumberEval(7) };
    AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues);
    AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues);
    ValueEval[] args = { aeA, aeB };
    ValueEval result = invokeSumproduct(args);
    confirmDouble(65D, 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