Search in sources :

Example 66 with NumberEval

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

the class TestEDate method checkValue.

private void checkValue(int startDate, int monthInc, double expectedResult) {
    EDate eDate = new EDate();
    NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[] { new NumberEval(startDate), new NumberEval(monthInc) }, null);
    assertEquals(expectedResult, result.getNumberValue(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 67 with NumberEval

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

the class TestEDate method testEDateIncrease.

@Test
public void testEDateIncrease() {
    EDate eDate = new EDate();
    Date startDate = new Date();
    int offset = 2;
    NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[] { new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset) }, null);
    Date resultDate = DateUtil.getJavaDate(result.getNumberValue());
    Calendar instance = LocaleUtil.getLocaleCalendar();
    instance.setTime(startDate);
    instance.add(Calendar.MONTH, offset);
    assertEquals(resultDate, instance.getTime());
}
Also used : Calendar(java.util.Calendar) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 68 with NumberEval

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

the class TestEOMonth method testEOMonthInvalidArguments.

@Test
public void testEOMonthInvalidArguments() {
    ValueEval result = eOMonth.evaluate(new ValueEval[] { new NumberEval(DATE_1902_09_26) }, ec);
    assertTrue(result instanceof ErrorEval);
    assertEquals(FormulaError.VALUE.getCode(), ((ErrorEval) result).getErrorCode(), 0);
    result = eOMonth.evaluate(new ValueEval[] { new StringEval("a"), new StringEval("b") }, ec);
    assertTrue(result instanceof ErrorEval);
    assertEquals(FormulaError.VALUE.getCode(), ((ErrorEval) result).getErrorCode(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 69 with NumberEval

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

the class TestEOMonth method testEOMonthBlankValueEval.

@Test
public void testEOMonthBlankValueEval() {
    NumberEval evaluate = (NumberEval) eOMonth.evaluate(new ValueEval[] { BlankEval.instance, new NumberEval(0) }, ec);
    assertEquals("Blank is handled as 0", DATE_1900_01_31, evaluate.getNumberValue(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 70 with NumberEval

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

the class TestEOMonth method testEOMonthBlankRefValueEval.

@Test
public void testEOMonthBlankRefValueEval() {
    ValueEval[] ve1 = { new RefEvalImplementation(BlankEval.instance), new NumberEval(1) };
    NumberEval result = (NumberEval) eOMonth.evaluate(ve1, ec);
    assertEquals("Blank is handled as 0", DATE_1900_02_28, result.getNumberValue(), 0);
    ValueEval[] ve2 = { new NumberEval(1), new RefEvalImplementation(BlankEval.instance) };
    result = (NumberEval) eOMonth.evaluate(ve2, ec);
    assertEquals("Blank is handled as 0", DATE_1900_01_31, result.getNumberValue(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

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