Search in sources :

Example 46 with NumberEval

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);
}
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 47 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AssertionFailedError(junit.framework.AssertionFailedError) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 48 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 49 with NumberEval

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 50 with NumberEval

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