use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestTrunc method testTruncWithDecimalNumber.
public void testTruncWithDecimalNumber() {
ValueEval[] args = { new NumberEval(2.612777), new NumberEval(3) };
@SuppressWarnings("static-access") ValueEval result = F.TRUNC.evaluate(args, -1, (short) -1);
assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval) result).getNumberValue());
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestValue method confirmValue.
private static void confirmValue(String strText, double expected) {
ValueEval result = invokeValue(strText);
assertEquals(NumberEval.class, result.getClass());
assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestXYNumericFunction 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.REF_INVALID);
confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION);
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestFunctionRegistry method testRegisterInRuntime.
public void testRegisterInRuntime() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFCell cellA = row.createCell(0);
cellA.setCellFormula("FISHER(A5)");
CellValue cv;
try {
cv = fe.evaluate(cellA);
fail("expectecd exception");
} catch (NotImplementedException e) {
}
FunctionEval.registerFunction("FISHER", new Function() {
@Override
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
return ErrorEval.NA;
}
});
cv = fe.evaluate(cellA);
assertEquals(ErrorEval.NA.getErrorCode(), cv.getErrorValue());
HSSFCell cellB = row.createCell(1);
cellB.setCellFormula("CUBEMEMBERPROPERTY(A5)");
try {
cv = fe.evaluate(cellB);
fail("expectecd exception");
} catch (NotImplementedException e) {
}
AnalysisToolPak.registerFunction("CUBEMEMBERPROPERTY", new FreeRefFunction() {
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
return ErrorEval.NUM_ERROR;
}
});
cv = fe.evaluate(cellB);
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), cv.getErrorValue());
}
use of org.apache.poi.ss.formula.eval.ValueEval in project poi by apache.
the class TestWorkbookEvaluator method testAttrSum.
/**
* Make sure that the evaluator can directly handle tAttrSum (instead of relying on re-parsing
* the whole formula which converts tAttrSum to tFuncVar("SUM") )
*/
@Test
public void testAttrSum() {
Ptg[] ptgs = { new IntPtg(42), AttrPtg.SUM };
ValueEval result = evaluateFormula(ptgs);
assertEquals(42, ((NumberEval) result).getNumberValue(), 0.0);
}
Aggregations