use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestPercentile method testUnusualArgs3.
//percentile has to be between 0 and 1 - here we test more than 1
public void testUnusualArgs3() {
ValueEval[] values = { new NumberEval(1), new NumberEval(2) };
ValueEval percentile = new NumberEval(1.1);
confirmPercentile(percentile, values, ErrorEval.NUM_ERROR);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestForkedEvaluator method testBasic.
/**
* Shows a basic use-case for {@link ForkedEvaluator}
*/
@Test
public void testBasic() throws IOException {
Workbook wb = createWorkbook();
// The stability classifier is useful to reduce memory consumption of caching logic
IStabilityClassifier stabilityClassifier = new IStabilityClassifier() {
@Override
public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
return sheetIndex == 1;
}
};
ForkedEvaluator fe1 = ForkedEvaluator.create(wb, stabilityClassifier, null);
ForkedEvaluator fe2 = ForkedEvaluator.create(wb, stabilityClassifier, null);
// fe1 and fe2 can be used concurrently on separate threads
fe1.updateCell("Inputs", 0, 0, new NumberEval(4.0));
fe1.updateCell("Inputs", 0, 1, new NumberEval(1.1));
fe2.updateCell("Inputs", 0, 0, new NumberEval(1.2));
fe2.updateCell("Inputs", 0, 1, new NumberEval(2.0));
assertEquals(18.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0));
assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
wb.close();
}
use of org.apache.poi.ss.formula.eval.NumberEval 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.NumberEval 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.NumberEval 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