Search in sources :

Example 61 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.

the class TestIndex method confirmAreaEval.

/**
	 * @param areaRefString in Excel notation e.g. 'D2:E97'
	 * @param dValues array of evaluated values for the area reference
	 * @param rowNum 1-based
	 * @param colNum 1-based, pass -1 to signify argument not present
	 */
private static void confirmAreaEval(String areaRefString, double[] dValues, int rowNum, int colNum, double expectedResult) {
    ValueEval[] values = new ValueEval[dValues.length];
    for (int i = 0; i < values.length; i++) {
        values[i] = new NumberEval(dValues[i]);
    }
    AreaEval arg0 = EvalFactory.createAreaEval(areaRefString, values);
    ValueEval[] args;
    if (colNum > 0) {
        args = new ValueEval[] { arg0, new NumberEval(rowNum), new NumberEval(colNum) };
    } else {
        args = new ValueEval[] { arg0, new NumberEval(rowNum) };
    }
    double actual = invokeAndDereference(args);
    assertEquals(expectedResult, actual, 0D);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 62 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.

the class TestEDate method testEDateInvalidValues.

@Test
public void testEDateInvalidValues() {
    EDate eDate = new EDate();
    ErrorEval result = (ErrorEval) eDate.evaluate(new ValueEval[] { new NumberEval(1000) }, null);
    assertEquals(FormulaError.VALUE.getCode(), result.getErrorCode(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 63 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.

the class TestEDate method testEDateInvalidValueEval.

@Test
public void testEDateInvalidValueEval() {
    ValueEval evaluate = new EDate().evaluate(new ValueEval[] { new ValueEval() {
    }, new NumberEval(0) }, null);
    assertTrue(evaluate instanceof ErrorEval);
    assertEquals(ErrorEval.VALUE_INVALID, evaluate);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 64 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.

the class TestLen method testUnusualArgs.

/**
	 * Valid cases where text arg is not exactly a string
	 */
public void testUnusualArgs() {
    // text (first) arg type is number, other args are strings with fractional digits
    confirmLen(new NumberEval(123456), 6);
    confirmLen(BoolEval.FALSE, 5);
    confirmLen(BoolEval.TRUE, 4);
    confirmLen(BlankEval.instance, 0);
}
Also used : NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 65 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.

the class TestIndex method invokeAndDereference.

private static double invokeAndDereference(ValueEval[] args) {
    ValueEval ve = FUNC_INST.evaluate(args, -1, -1);
    ve = WorkbookEvaluator.dereferenceResult(ve, -1, -1);
    assertEquals(NumberEval.class, ve.getClass());
    return ((NumberEval) ve).getNumberValue();
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) 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