Search in sources :

Example 36 with ValueEval

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

the class TestSumproduct method testMismatchAreaDimensions.

public void testMismatchAreaDimensions() {
    AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]);
    AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]);
    ValueEval[] args;
    args = new ValueEval[] { aeA, aeB };
    assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
    args = new ValueEval[] { aeA, new NumberEval(5) };
    assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) 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 37 with ValueEval

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

the class TestSumproduct method testScalarSimple.

public void testScalarSimple() {
    RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
    ValueEval[] args = { refEval, new NumberEval(2) };
    ValueEval result = invokeSumproduct(args);
    confirmDouble(6D, result);
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 38 with ValueEval

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

the class TestSumproduct method testAreaSimple.

public void testAreaSimple() {
    ValueEval[] aValues = { new NumberEval(2), new NumberEval(4), new NumberEval(5) };
    ValueEval[] bValues = { new NumberEval(3), new NumberEval(6), new NumberEval(7) };
    AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues);
    AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues);
    ValueEval[] args = { aeA, aeB };
    ValueEval result = invokeSumproduct(args);
    confirmDouble(65D, result);
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) 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 39 with ValueEval

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

the class TestText method testTextWithDeciamlFormatSecondArg.

@Test
public void testTextWithDeciamlFormatSecondArg() {
    ValueEval numArg = new NumberEval(321321.321);
    ValueEval formatArg = new StringEval("#,###.00000");
    ValueEval[] args = { numArg, formatArg };
    ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
    char groupSeparator = dfs.getGroupingSeparator();
    char decimalSeparator = dfs.getDecimalSeparator();
    ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
    assertEquals(testResult.toString(), result.toString());
    numArg = new NumberEval(321.321);
    formatArg = new StringEval("00000.00000");
    args[0] = numArg;
    args[1] = formatArg;
    result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    testResult = new StringEval("00321" + decimalSeparator + "32100");
    assertEquals(testResult.toString(), result.toString());
    formatArg = new StringEval("$#.#");
    args[1] = formatArg;
    result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    testResult = new StringEval("$321" + decimalSeparator + "3");
    assertEquals(testResult.toString(), result.toString());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 40 with ValueEval

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

the class TestText method testTextWithStringFirstArg.

@Test
public void testTextWithStringFirstArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval formatArg = new StringEval("abc");
    ValueEval[] args = { strArg, formatArg };
    ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) Test(org.junit.Test)

Aggregations

ValueEval (org.apache.poi.ss.formula.eval.ValueEval)223 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)101 StringEval (org.apache.poi.ss.formula.eval.StringEval)48 Test (org.junit.Test)39 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)36 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)29 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)28 OperationEvaluationContext (org.apache.poi.ss.formula.OperationEvaluationContext)27 Calendar (java.util.Calendar)16 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)13 Date (java.util.Date)11 RefEval (org.apache.poi.ss.formula.eval.RefEval)9 TwoDEval (org.apache.poi.ss.formula.TwoDEval)7 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)4 NotImplementedException (org.apache.poi.ss.formula.eval.NotImplementedException)4 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)4 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)4 ArrayList (java.util.ArrayList)3 AssertionFailedError (junit.framework.AssertionFailedError)3 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3