Search in sources :

Example 16 with NumberEval

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

the class TestSumif method testBasic.

public void testBasic() {
    ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 };
    ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 };
    AreaEval arg0;
    AreaEval arg2;
    arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
    arg2 = EvalFactory.createAreaEval("D1:E3", arg2values);
    confirm(60.0, arg0, new NumberEval(30.0));
    confirm(70.0, arg0, new NumberEval(30.0), arg2);
    confirm(100.0, arg0, new StringEval(">45"));
    confirm(100.0, arg0, new StringEval(">=45"));
    confirm(100.0, arg0, new StringEval(">=50.0"));
    confirm(140.0, arg0, new StringEval("<45"));
    confirm(140.0, arg0, new StringEval("<=45"));
    confirm(140.0, arg0, new StringEval("<=40.0"));
    confirm(160.0, arg0, new StringEval("<>40.0"));
    confirm(80.0, arg0, new StringEval("=40.0"));
}
Also used : NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 17 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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 18 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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 19 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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 20 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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)

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