Search in sources :

Example 16 with StringEval

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

the class TestMatch method testInvalidMatchType.

public void testInvalidMatchType() {
    ValueEval[] values = { new NumberEval(4), new NumberEval(5), new NumberEval(10), new NumberEval(10), new NumberEval(25) };
    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
    confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    assertEquals("Should return #REF! for invalid match type", ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID));
}
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 StringEval

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

the class TestMatch method testTildeString.

public void testTildeString() {
    ValueEval[] values = { new StringEval("what?"), new StringEval("all*") };
    AreaEval ae = EvalFactory.createAreaEval("A1:A2", values);
    confirmInt(1, invokeMatch(new StringEval("what~?"), ae, MATCH_EXACT));
    confirmInt(2, invokeMatch(new StringEval("all~*"), ae, MATCH_EXACT));
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 18 with StringEval

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

the class TestMid method testUnusualArgs.

/**
	 * Valid cases where args are not precisely (string, int, int) but can be resolved OK.
	 */
public void testUnusualArgs() {
    // startPos with fractional digits
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
    // string startPos
    confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
    // text (first) arg type is number, other args are strings with fractional digits
    confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
    // startPos is 1x1 area ref, numChars is cell ref
    AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2) });
    RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
    confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
    confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) 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 19 with StringEval

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

the class TestMid method testErrors.

/**
	 * All sorts of ways to make MID return defined errors.
	 */
public void testErrors() {
    confirmMid(ErrorEval.NAME_INVALID, new NumberEval(3), new NumberEval(4), ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), ErrorEval.NAME_INVALID, new NumberEval(4), ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(3), ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
    confirmMid(new StringEval("galactic"), ErrorEval.DIV_ZERO, ErrorEval.NAME_INVALID, ErrorEval.DIV_ZERO);
    confirmMid(new StringEval("galactic"), BlankEval.instance, new NumberEval(3.1), ErrorEval.VALUE_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(0), new NumberEval(4), ErrorEval.VALUE_INVALID);
    confirmMid(new StringEval("galactic"), new NumberEval(1), new NumberEval(-1), ErrorEval.VALUE_INVALID);
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 20 with StringEval

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

the class TestCountFuncs method testCountA.

public void testCountA() {
    ValueEval[] args;
    args = new ValueEval[] { new NumberEval(0) };
    confirmCountA(1, args);
    args = new ValueEval[] { new NumberEval(0), new NumberEval(0), new StringEval("") };
    confirmCountA(3, args);
    args = new ValueEval[] { EvalFactory.createAreaEval("D2:F5", new ValueEval[12]) };
    confirmCountA(12, args);
    args = new ValueEval[] { EvalFactory.createAreaEval("D1:F5", new ValueEval[15]), EvalFactory.createRefEval("A1"), EvalFactory.createAreaEval("A1:G6", new ValueEval[42]), new NumberEval(0) };
    confirmCountA(59, args);
}
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)

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