Search in sources :

Example 86 with ValueEval

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

the class TestDec2Bin method testWithTooManyParamsIntInt.

public void testWithTooManyParamsIntInt() {
    OperationEvaluationContext ctx = createContext();
    ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 1), ctx.getRefEval(0, 1) };
    ValueEval result = new Dec2Bin().evaluate(args, -1, -1);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) ValueEval(org.apache.poi.ss.formula.eval.ValueEval)

Example 87 with ValueEval

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

the class TestHex2Dec method testEvalOperationEvaluationContext.

public void testEvalOperationEvaluationContext() {
    OperationEvaluationContext ctx = createContext();
    ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0) };
    ValueEval result = new Hex2Dec().evaluate(args, ctx);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals("0", ((NumberEval) result).getStringValue());
}
Also used : OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) ValueEval(org.apache.poi.ss.formula.eval.ValueEval)

Example 88 with ValueEval

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

the class TestHex2Dec method testEvalOperationEvaluationContextFails.

public void testEvalOperationEvaluationContextFails() {
    OperationEvaluationContext ctx = createContext();
    ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 0) };
    ValueEval result = new Hex2Dec().evaluate(args, ctx);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : OperationEvaluationContext(org.apache.poi.ss.formula.OperationEvaluationContext) ValueEval(org.apache.poi.ss.formula.eval.ValueEval)

Example 89 with ValueEval

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

the class TestIndex method testReferenceResult.

/**
	 * When the argument to INDEX is a reference, the result should be a reference
	 * A formula like "OFFSET(INDEX(A1:B2,2,1),1,1,1,1)" should return the value of cell B3.
	 * This works because the INDEX() function returns a reference to A2 (not the value of A2)
	 */
public void testReferenceResult() {
    ValueEval[] values = new ValueEval[4];
    Arrays.fill(values, NumberEval.ZERO);
    AreaEval arg0 = EvalFactory.createAreaEval("A1:B2", values);
    ValueEval[] args = new ValueEval[] { arg0, new NumberEval(2), new NumberEval(1) };
    ValueEval ve = FUNC_INST.evaluate(args, -1, -1);
    confirmAreaEval("A2:A2", ve);
}
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 90 with ValueEval

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

Aggregations

ValueEval (org.apache.poi.ss.formula.eval.ValueEval)223 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)101 StringEval (org.apache.poi.ss.formula.eval.StringEval)48 Test (org.junit.Test)39 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)36 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)29 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)28 OperationEvaluationContext (org.apache.poi.ss.formula.OperationEvaluationContext)27 Calendar (java.util.Calendar)16 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)13 Date (java.util.Date)11 RefEval (org.apache.poi.ss.formula.eval.RefEval)9 TwoDEval (org.apache.poi.ss.formula.TwoDEval)7 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)4 NotImplementedException (org.apache.poi.ss.formula.eval.NotImplementedException)4 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)4 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)4 ArrayList (java.util.ArrayList)3 AssertionFailedError (junit.framework.AssertionFailedError)3 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3