Search in sources :

Example 36 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 37 with NumberEval

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();
}
Also used : IStabilityClassifier(org.apache.poi.ss.formula.IStabilityClassifier) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 38 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 39 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 40 with NumberEval

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"));
}
Also used : 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)

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