use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestIndex method testReferenceResult.
/**
* When the argument to INDEX is a reference, the result should be a reference
* A formula like "OFFSET(INDEX(A1:B2,2,1),1,1,1,1)" should return the value of cell B3.
* This works because the INDEX() function returns a reference to A2 (not the value of A2)
*/
public void testReferenceResult() {
ValueEval[] values = new ValueEval[4];
Arrays.fill(values, NumberEval.ZERO);
AreaEval arg0 = EvalFactory.createAreaEval("A1:B2", values);
ValueEval[] args = new ValueEval[] { arg0, new NumberEval(2), new NumberEval(1) };
ValueEval ve = FUNC_INST.evaluate(args, -1, -1);
confirmAreaEval("A2:A2", ve);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestIndex method testMissingArg.
/**
* Tests expressions like "INDEX(A1:C1,,2)".<br/>
* This problem was found while fixing bug 47048 and is observable up to svn r773441.
*/
public void testMissingArg() {
ValueEval[] values = { new NumberEval(25.0), new NumberEval(26.0), new NumberEval(28.0) };
AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2) };
ValueEval actualResult;
try {
actualResult = FUNC_INST.evaluate(args, -1, -1);
} catch (RuntimeException e) {
if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) {
throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg");
}
throw e;
}
// result should be an area eval "B10:B10"
AreaEval ae = confirmAreaEval("B10:B10", actualResult);
actualResult = ae.getValue(0, 0);
assertEquals(NumberEval.class, actualResult.getClass());
assertEquals(26.0, ((NumberEval) actualResult).getNumberValue(), 0.0);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestEDate method testEDateBlankRefValueEval.
@Test
public void testEDateBlankRefValueEval() {
EDate eDate = new EDate();
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[] { new RefEvalImplementation(BlankEval.instance), new NumberEval(0) }, null);
assertEquals("0 startDate triggers BAD_DATE currently, thus -1.0!", -1.0d, result.getNumberValue(), 0);
result = (NumberEval) eDate.evaluate(new ValueEval[] { new NumberEval(1), new RefEvalImplementation(BlankEval.instance) }, null);
assertEquals("Blank is handled as 0 otherwise", 1.0d, result.getNumberValue(), 0);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestEDate method testEDateBlankValueEval.
@Test
public void testEDateBlankValueEval() {
NumberEval evaluate = (NumberEval) new EDate().evaluate(new ValueEval[] { BlankEval.instance, new NumberEval(0) }, null);
assertEquals(-1.0d, evaluate.getNumberValue(), 0);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestEDate method testRefEvalStartDate.
@Test
public void testRefEvalStartDate() {
EDate eDate = new EDate();
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[] { new RefEvalImplementation(new NumberEval(1000)), new NumberEval(0) }, null);
assertEquals(1000d, result.getNumberValue(), 0);
}
Aggregations