Search in sources :

Example 86 with NumberEval

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

the class TestText method testTextWithFractionFormatSecondArg.

@Test
public void testTextWithFractionFormatSecondArg() {
    ValueEval numArg = new NumberEval(321.321);
    ValueEval formatArg = new StringEval("# #/#");
    ValueEval[] args = { numArg, formatArg };
    ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    ValueEval testResult = new StringEval("321 1/3");
    assertEquals(testResult.toString(), result.toString());
    formatArg = new StringEval("# #/##");
    args[1] = formatArg;
    result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    testResult = new StringEval("321 26/81");
    assertEquals(testResult.toString(), result.toString());
    formatArg = new StringEval("#/##");
    args[1] = formatArg;
    result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
    testResult = new StringEval("26027/81");
    assertEquals(testResult.toString(), result.toString());
}
Also used : 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 87 with NumberEval

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

the class TestTrim method testUnusualArgs.

/**
	 * Valid cases where text arg is not exactly a string
	 */
public void testUnusualArgs() {
    // text (first) arg type is number, other args are strings with fractional digits
    confirmTrim(new NumberEval(123456), "123456");
    confirmTrim(BoolEval.FALSE, "FALSE");
    confirmTrim(BoolEval.TRUE, "TRUE");
    confirmTrim(BlankEval.instance, "");
}
Also used : NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 88 with NumberEval

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

the class TestTrunc method testTruncWithStringArg.

public void testTruncWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.TRUNC.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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 89 with NumberEval

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

the class TestRoundFuncs method testRoundDownWithStringArg.

@Test
public void testRoundDownWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.ROUNDDOWN.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) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 90 with NumberEval

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

the class TestRoundFuncs method testRoundUpWithStringArg.

@Test
public void testRoundUpWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.ROUNDUP.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) 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