Search in sources :

Example 6 with ErrorEval

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

the class TestPmt method test3args.

@Test
public void test3args() {
    ValueEval[] args = { new NumberEval(0.005), new NumberEval(24), new NumberEval(1000) };
    ValueEval ev = invoke(args);
    if (ev instanceof ErrorEval) {
        ErrorEval err = (ErrorEval) ev;
        if (err.getErrorCode() == FormulaError.VALUE.getCode()) {
            fail("Identified bug 44691");
        }
    }
    confirm(-44.3206, invokeNormal(args));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 7 with ErrorEval

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

the class TestPoisson method testNegativeMean.

public void testNegativeMean() {
    double x = 0;
    double mean = -0.2;
    ErrorEval myResult = (ErrorEval) invokePoisson(x, mean, false);
    assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), myResult.getErrorCode());
}
Also used : ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval)

Example 8 with ErrorEval

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

the class NumericFunctionInvoker method invokeInternal.

/**
	 * Formats nicer error messages for the junit output
	 */
private static double invokeInternal(Function target, ValueEval[] args, int srcCellRow, int srcCellCol) throws NumericEvalEx {
    ValueEval evalResult;
    try {
        evalResult = target.evaluate(args, srcCellRow, (short) srcCellCol);
    } catch (NotImplementedException e) {
        throw new NumericEvalEx("Not implemented:" + e.getMessage());
    }
    if (evalResult == null) {
        throw new NumericEvalEx("Result object was null");
    }
    if (evalResult instanceof ErrorEval) {
        ErrorEval ee = (ErrorEval) evalResult;
        throw new NumericEvalEx(formatErrorMessage(ee));
    }
    if (!(evalResult instanceof NumericValueEval)) {
        throw new NumericEvalEx("Result object type (" + evalResult.getClass().getName() + ") is invalid.  Expected implementor of (" + NumericValueEval.class.getName() + ")");
    }
    NumericValueEval result = (NumericValueEval) evalResult;
    return result.getNumberValue();
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) NotImplementedException(org.apache.poi.ss.formula.eval.NotImplementedException) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval)

Example 9 with ErrorEval

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

the class TestFixed method testOptionalParams.

@Test
public void testOptionalParams() {
    Fixed fixed = new Fixed();
    ValueEval evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789));
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1,234.57", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1));
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1,234.6", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1), BoolEval.TRUE);
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1234.6", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(new ValueEval[] {}, 1, 1);
    assertTrue(evaluate instanceof ErrorEval);
    evaluate = fixed.evaluate(new ValueEval[] { new NumberEval(1), new NumberEval(1), new NumberEval(1), new NumberEval(1) }, 1, 1);
    assertTrue(evaluate instanceof ErrorEval);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 10 with ErrorEval

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

the class TestEDate method testEDateInvalidValues.

@Test
public void testEDateInvalidValues() {
    EDate eDate = new EDate();
    ErrorEval result = (ErrorEval) eDate.evaluate(new ValueEval[] { new NumberEval(1000) }, null);
    assertEquals(FormulaError.VALUE.getCode(), result.getErrorCode(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Aggregations

ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)17 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)13 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)8 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)5 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)5 StringEval (org.apache.poi.ss.formula.eval.StringEval)5 Test (org.junit.Test)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)2 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)2 EvaluationCell (org.apache.poi.ss.formula.EvaluationCell)1 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)1 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)1 NotImplementedException (org.apache.poi.ss.formula.eval.NotImplementedException)1 RefEval (org.apache.poi.ss.formula.eval.RefEval)1 CellValue (org.apache.poi.ss.usermodel.CellValue)1