Search in sources :

Example 26 with NumberEval

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

the class TestPoisson method testNonCumulativeProbability.

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

Example 27 with NumberEval

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

the class TestPoisson method invokePoisson.

private static ValueEval invokePoisson(double x, double mean, boolean cumulative) {
    ValueEval[] valueEvals = new ValueEval[3];
    valueEvals[0] = new NumberEval(x);
    valueEvals[1] = new NumberEval(mean);
    valueEvals[2] = BoolEval.valueOf(cumulative);
    return NumericFunction.POISSON.evaluate(valueEvals, -1, -1);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 28 with NumberEval

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

the class TestMatch method testInvalidMatchType.

public void testInvalidMatchType() {
    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));
    assertEquals("Should return #REF! for invalid match type", ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID));
}
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 29 with NumberEval

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

the class TestMid method testUnusualArgs.

/**
	 * Valid cases where args are not precisely (string, int, int) but can be resolved OK.
	 */
public void testUnusualArgs() {
    // startPos with fractional digits
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
    // string startPos
    confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
    // text (first) arg type is number, other args are strings with fractional digits
    confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
    // startPos is 1x1 area ref, numChars is cell ref
    AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2) });
    RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
    confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
    confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) 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 30 with NumberEval

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

the class TestMid method testErrors.

/**
	 * All sorts of ways to make MID return defined errors.
	 */
public void testErrors() {
    confirmMid(ErrorEval.NAME_INVALID, new NumberEval(3), new NumberEval(4), ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), ErrorEval.NAME_INVALID, new NumberEval(4), ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(3), ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), ErrorEval.DIV_ZERO, ErrorEval.NAME_INVALID, ErrorEval.DIV_ZERO);
    confirmMid(new StringEval("galactic"), BlankEval.instance, new NumberEval(3.1), ErrorEval.VALUE_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(0), new NumberEval(4), ErrorEval.VALUE_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(1), new NumberEval(-1), ErrorEval.VALUE_INVALID);
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) 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