Search in sources :

Example 21 with NumberEval

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

the class TestTrunc method testTruncWithDecimalNumberOneArg.

public void testTruncWithDecimalNumberOneArg() {
    ValueEval[] args = { new NumberEval(2.612777) };
    ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short) -1);
    assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval) result).getNumberValue());
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 22 with NumberEval

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

the class TestSlope method testErrors.

public void testErrors() {
    ValueEval[] xValues = { ErrorEval.REF_INVALID, new NumberEval(2) };
    ValueEval areaEvalX = createAreaEval(xValues);
    ValueEval[] yValues = { new NumberEval(2), ErrorEval.NULL_INTERSECTION };
    ValueEval areaEvalY = createAreaEval(yValues);
    ValueEval[] zValues = { // wrong size
    new NumberEval(2) };
    ValueEval areaEvalZ = createAreaEval(zValues);
    // if either arg is an error, that error propagates
    confirmError(ErrorEval.REF_INVALID, ErrorEval.NAME_INVALID, ErrorEval.REF_INVALID);
    confirmError(areaEvalX, ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
    confirmError(ErrorEval.NAME_INVALID, areaEvalX, ErrorEval.NAME_INVALID);
    // array sizes must match
    confirmError(areaEvalX, areaEvalZ, ErrorEval.NA);
    confirmError(areaEvalZ, areaEvalY, ErrorEval.NA);
    // any error in an array item propagates up
    confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
    // search for errors array by array, not pair by pair
    confirmError(areaEvalX, areaEvalY, ErrorEval.NULL_INTERSECTION);
    confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 23 with NumberEval

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

the class TestSlope method testLargeArrays.

/**
	 * number of items in array is not limited to 30
	 */
public void testLargeArrays() {
    // [1,2,0,1,2,0,...,0,1]
    ValueEval[] yValues = createMockNumberArray(100, 3);
    // Changes first element to 2
    yValues[0] = new NumberEval(2.0);
    // [1,2,3,4,...,99,100]
    ValueEval[] xValues = createMockNumberArray(100, 101);
    confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
// Excel 2010 gives -1.23152709359606
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 24 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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 25 with NumberEval

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

the class TestPoisson method testXAsDecimalNumber.

public void testXAsDecimalNumber() {
    double x = 1.1;
    double mean = 0.2;
    // known result
    double result = 0.9824769036935787;
    NumberEval myResult = (NumberEval) invokePoisson(x, mean, true);
    assertEquals(myResult.getNumberValue(), result, DELTA);
}
Also used : NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

NumberEval (org.apache.poi.ss.formula.eval.NumberEval)123 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)101 Test (org.junit.Test)34 StringEval (org.apache.poi.ss.formula.eval.StringEval)29 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)21 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)19 Calendar (java.util.Calendar)17 Date (java.util.Date)13 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)12 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)5 RefEval (org.apache.poi.ss.formula.eval.RefEval)4 AssertionFailedError (junit.framework.AssertionFailedError)3 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 SimpleDateFormat (java.text.SimpleDateFormat)1