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);
}
}
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
}
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);
}
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
}
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();
}
Aggregations