Search in sources :

Example 26 with StringEval

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

the class TestWorkdayFunction method testReturnWorkdays.

@Test
public void testReturnWorkdays() {
    Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 3, 30);
    Date expDate = expCal.getTime();
    ValueEval[] ve = { new StringEval(STARTING_DATE), new NumberEval(151) };
    Date actDate = DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue());
    assertEquals(expDate, actDate);
}
Also used : Calendar(java.util.Calendar) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 27 with StringEval

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

the class TestWorkdayFunction method testReturnWorkdaysSpanningAWeekendAddingDays.

@Test
public void testReturnWorkdaysSpanningAWeekendAddingDays() {
    Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 8, 30);
    Date expDate = expCal.getTime();
    ValueEval[] ve = { new StringEval("2013/09/27"), new NumberEval(1) };
    double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
    assertEquals(41547.0, numberValue, 0);
    Date actDate = DateUtil.getJavaDate(numberValue);
    assertEquals(expDate, actDate);
}
Also used : Calendar(java.util.Calendar) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 28 with StringEval

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

the class TestMid method testExtremes.

/**
	 * Extreme values for startPos and numChars
	 */
public void testExtremes() {
    confirmMid(new StringEval("galactic"), new NumberEval(4), new NumberEval(400), "actic");
    confirmMid(new StringEval("galactic"), new NumberEval(30), new NumberEval(4), "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), new NumberEval(0), "");
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 29 with StringEval

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

the class TestFixed method testOptionalParams.

@Test
public void testOptionalParams() {
    Fixed fixed = new Fixed();
    ValueEval evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789));
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1,234.57", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1));
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1,234.6", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1), BoolEval.TRUE);
    assertTrue(evaluate instanceof StringEval);
    assertEquals("1234.6", ((StringEval) evaluate).getStringValue());
    evaluate = fixed.evaluate(new ValueEval[] {}, 1, 1);
    assertTrue(evaluate instanceof ErrorEval);
    evaluate = fixed.evaluate(new ValueEval[] { new NumberEval(1), new NumberEval(1), new NumberEval(1), new NumberEval(1) }, 1, 1);
    assertTrue(evaluate instanceof ErrorEval);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 30 with StringEval

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

the class TestEOMonth method testEOMonthInvalidArguments.

@Test
public void testEOMonthInvalidArguments() {
    ValueEval result = eOMonth.evaluate(new ValueEval[] { new NumberEval(DATE_1902_09_26) }, ec);
    assertTrue(result instanceof ErrorEval);
    assertEquals(FormulaError.VALUE.getCode(), ((ErrorEval) result).getErrorCode(), 0);
    result = eOMonth.evaluate(new ValueEval[] { new StringEval("a"), new StringEval("b") }, ec);
    assertTrue(result instanceof ErrorEval);
    assertEquals(FormulaError.VALUE.getCode(), ((ErrorEval) result).getErrorCode(), 0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Aggregations

StringEval (org.apache.poi.ss.formula.eval.StringEval)58 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)48 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)29 Test (org.junit.Test)18 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)13 Calendar (java.util.Calendar)10 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)10 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)9 Date (java.util.Date)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)7 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 BigDecimal (java.math.BigDecimal)1 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1