use of org.apache.poi.ss.formula.eval.ValueEval 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();
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestAverage method testUnusualArgs.
/**
* Valid cases where values are not pure numbers
*/
public void testUnusualArgs() {
ValueEval[] values = { new NumberEval(1), new NumberEval(2), BoolEval.TRUE, BoolEval.FALSE };
confirmAverage(values, 1.0);
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestComplex method confirmValueError.
private static void confirmValueError(String msg, String real_num, String i_num, String suffix, ErrorEval numError) {
ValueEval result = invokeValue(real_num, i_num, suffix);
assertEquals(ErrorEval.class, result.getClass());
assertEquals(msg, numError, result);
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestCountFuncs method testCountA.
public void testCountA() {
ValueEval[] args;
args = new ValueEval[] { new NumberEval(0) };
confirmCountA(1, args);
args = new ValueEval[] { new NumberEval(0), new NumberEval(0), new StringEval("") };
confirmCountA(3, args);
args = new ValueEval[] { EvalFactory.createAreaEval("D2:F5", new ValueEval[12]) };
confirmCountA(12, args);
args = new ValueEval[] { EvalFactory.createAreaEval("D1:F5", new ValueEval[15]), EvalFactory.createRefEval("A1"), EvalFactory.createAreaEval("A1:G6", new ValueEval[42]), new NumberEval(0) };
confirmCountA(59, args);
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestCountFuncs method testCountIf.
public void testCountIf() {
AreaEval range;
ValueEval[] values;
// when criteria is a boolean value
values = new ValueEval[] { new NumberEval(0), // note - does not match boolean TRUE
new StringEval("TRUE"), BoolEval.TRUE, BoolEval.FALSE, BoolEval.TRUE, BlankEval.instance };
range = EvalFactory.createAreaEval("A1:B3", values);
confirmCountIf(2, range, BoolEval.TRUE);
// when criteria is numeric
values = new ValueEval[] { new NumberEval(0), new StringEval("2"), new StringEval("2.001"), new NumberEval(2), new NumberEval(2), BoolEval.TRUE };
range = EvalFactory.createAreaEval("A1:B3", values);
confirmCountIf(3, range, new NumberEval(2));
// note - same results when criteria is a string that parses as the number with the same value
confirmCountIf(3, range, new StringEval("2.00"));
// when criteria is an expression (starting with a comparison operator)
confirmCountIf(2, range, new StringEval(">1"));
// when criteria is an expression (starting with a comparison operator)
confirmCountIf(2, range, new StringEval(">0.5"));
}
Aggregations