Search in sources :

Example 71 with NumberEval

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

the class TestEOMonth method checkOffset.

@Test
public void checkOffset() {
    for (int offset = -12; offset <= 12; offset++) {
        Calendar cal = LocaleUtil.getLocaleCalendar();
        Date startDate = cal.getTime();
        cal.add(Calendar.MONTH, offset);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        cal.clear(Calendar.HOUR);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.clear(Calendar.MINUTE);
        cal.clear(Calendar.SECOND);
        cal.clear(Calendar.MILLISECOND);
        Date expDate = cal.getTime();
        ValueEval[] ve = { new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset) };
        NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
        Date actDate = DateUtil.getJavaDate(result.getNumberValue());
        assertEquals(expDate, actDate);
    }
}
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 72 with NumberEval

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

the class TestIntercept method testBasic.

public void testBasic() {
    Double exp = Math.pow(10, 7.5);
    ValueEval[] yValues = { new NumberEval(3 + exp), new NumberEval(4 + exp), new NumberEval(2 + exp), new NumberEval(5 + exp), new NumberEval(4 + exp), new NumberEval(7 + exp) };
    ValueEval areaEvalY = createAreaEval(yValues);
    ValueEval[] xValues = { new NumberEval(1), new NumberEval(2), new NumberEval(3), new NumberEval(4), new NumberEval(5), new NumberEval(6) };
    ValueEval areaEvalX = createAreaEval(xValues);
    confirm(INTERCEPT, areaEvalX, areaEvalY, -24516534.39905822);
// Excel 2010 gives -24516534.3990583
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 73 with NumberEval

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

the class TestIntercept 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.NULL_INTERSECTION);
    confirmError(areaEvalY, areaEvalX, ErrorEval.REF_INVALID);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 74 with NumberEval

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

the class TestIntercept method testLargeArrays.

/**
	 * number of items in array is not limited to 30
	 */
public void testLargeArrays() {
    // [1,2,0,1,2,0,...,0,1]
    ValueEval[] yValues = createMockNumberArray(100, 3);
    // Changes first element to 2
    yValues[0] = new NumberEval(2.0);
    // [1,2,3,4,...,99,100]
    ValueEval[] xValues = createMockNumberArray(100, 101);
    confirm(INTERCEPT, createAreaEval(xValues), createAreaEval(yValues), 51.74384236453202);
// Excel 2010 gives 51.74384236453200
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 75 with NumberEval

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

the class TestXSSFBugs method testBug56688_4.

@Test
public void testBug56688_4() throws IOException {
    XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_4.xlsx");
    Calendar calendar = LocaleUtil.getLocaleCalendar();
    calendar.add(Calendar.MONTH, 2);
    double excelDate = DateUtil.getExcelDate(calendar.getTime());
    NumberEval eval = new NumberEval(Math.floor(excelDate));
    checkValue(excel, eval.getStringValue() + ".0");
    excel.close();
}
Also used : Calendar(java.util.Calendar) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) 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