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);
}
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);
}
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));
}
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, "");
}
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);
}
Aggregations