Package org.apache.poi.ss.formula.eval

Examples of org.apache.poi.ss.formula.eval.ValueEval


    ValueEval result = invoke(function, xArray, yArray);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
  }
  private void confirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
    ValueEval result = invoke(function, xArray, yArray);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
  }
View Full Code Here


      new NumberEval(2+exp),
      new NumberEval(5+exp),
      new NumberEval(4+exp),
      new NumberEval(7+exp),
    };
    ValueEval areaEvalY = createAreaEval(yValues);

    ValueEval[] xValues = {
      new NumberEval(1),
      new NumberEval(2),
      new NumberEval(3),
      new NumberEval(4),
      new NumberEval(5),
      new NumberEval(6),
    };
    ValueEval areaEvalX = createAreaEval(xValues);
    confirm(SLOPE, areaEvalX, areaEvalY, 0.7752808988764045);
    // Excel 2010 gives 0.775280898876405
  }
View Full Code Here

  public void testErrors() {
    ValueEval[] xValues = {
        ErrorEval.REF_INVALID,
        new NumberEval(2),
    };
    ValueEval areaEvalX = createAreaEval(xValues);
    ValueEval[] yValues = {
        new NumberEval(2),
        ErrorEval.NULL_INTERSECTION,
    };
    ValueEval areaEvalY = createAreaEval(yValues);
    ValueEval[] zValues = { // wrong size
        new NumberEval(2),
    };
    ValueEval areaEvalZ = createAreaEval(zValues);

    // if either arg is an error, that error propagates
    confirmError(ErrorEval.REF_INVALID, ErrorEval.NAME_INVALID, ErrorEval.REF_INVALID);
    confirmError(areaEvalX, ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
    confirmError(ErrorEval.NAME_INVALID, areaEvalX, ErrorEval.NAME_INVALID);
View Full Code Here

public final class TestText extends TestCase {
  private static final TextFunction T = null;

  public void testTextWithStringFirstArg() {

    ValueEval strArg = new StringEval("abc");
    ValueEval formatArg = new StringEval("abc");
    ValueEval[] args = { strArg, formatArg };
    ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
  }
View Full Code Here

    assertEquals(ErrorEval.VALUE_INVALID, result);
  }

  public void testTextWithDeciamlFormatSecondArg() {

    ValueEval numArg = new NumberEval(321321.321);
    ValueEval formatArg = new StringEval("#,###.00000");
    ValueEval[] args = { numArg, formatArg };
    ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
    char groupSeparator = new DecimalFormatSymbols(Locale.getDefault()).getGroupingSeparator();
    char decimalSeparator = new DecimalFormatSymbols(Locale.getDefault()).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 = T.TEXT.evaluate(args, -1, (short)-1);
    testResult = new StringEval("00321" + decimalSeparator + "32100");
    assertEquals(testResult.toString(), result.toString());

    formatArg = new StringEval("$#.#");
    args[1] = formatArg;
    result = T.TEXT.evaluate(args, -1, (short)-1);
    testResult = new StringEval("$321" + decimalSeparator + "3");
    assertEquals(testResult.toString(), result.toString());
  }
View Full Code Here

    assertEquals(testResult.toString(), result.toString());
  }

  public void testTextWithFractionFormatSecondArg() {

    ValueEval numArg = new NumberEval(321.321);
    ValueEval formatArg = new StringEval("# #/#");
    ValueEval[] args = { numArg, formatArg };
    ValueEval result = T.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 = T.TEXT.evaluate(args, -1, (short)-1);
    testResult = new StringEval("321 26/81");
    assertEquals(testResult.toString(), result.toString());

    formatArg = new StringEval("#/##");
    args[1] = formatArg;
    result = T.TEXT.evaluate(args, -1, (short)-1);
    testResult = new StringEval("26027/81");
    assertEquals(testResult.toString(), result.toString());
  }
View Full Code Here

    assertEquals(testResult.toString(), result.toString());
  }

   public void testTextWithDateFormatSecondArg() {
      // Test with Java style M=Month
      ValueEval numArg = new NumberEval(321.321);
      ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");
      ValueEval[] args = { numArg, formatArg };
      ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
      ValueEval testResult = new StringEval("16:11:1900 07:42:14");
      assertEquals(testResult.toString(), result.toString());

      // Excel also supports "m before h is month"
      formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
      args[1] = formatArg;
      result = T.TEXT.evaluate(args, -1, (short)-1);
      testResult = new StringEval("16:11:1900 07:42:14");
      assertEquals(testResult.toString(), result.toString());

      // this line is intended to compute how "November" would look like in the current locale
      String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());

      // Again with Java style
      formatArg = new StringEval("MMMM dd, yyyy");
      args[1] = formatArg;
      result = T.TEXT.evaluate(args, -1, (short)-1);
      testResult = new StringEval(november + " 16, 1900");
      assertEquals(testResult.toString(), result.toString());

      // And Excel style
      formatArg = new StringEval("mmmm dd, yyyy");
      args[1] = formatArg;
      result = T.TEXT.evaluate(args, -1, (short)-1);
      testResult = new StringEval(november + " 16, 1900");
      assertEquals(testResult.toString(), result.toString());
   }
View Full Code Here

    ValueEval[] args = new ValueEval[] { xArray, yArray, };
    return function.evaluate(args, -1, (short)-1);
  }

  private void confirm(Function function, ValueEval xArray, ValueEval yArray, double expected) {
    ValueEval result = invoke(function, xArray, yArray);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
  }
View Full Code Here

    ValueEval result = invoke(function, xArray, yArray);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
  }
  private void confirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
    ValueEval result = invoke(function, xArray, yArray);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
  }
View Full Code Here

      new NumberEval(2+exp),
      new NumberEval(5+exp),
      new NumberEval(4+exp),
      new NumberEval(7+exp),
    };
    ValueEval areaEvalY = createAreaEval(yValues);

    ValueEval[] xValues = {
      new NumberEval(1),
      new NumberEval(2),
      new NumberEval(3),
      new NumberEval(4),
      new NumberEval(5),
      new NumberEval(6),
    };
    ValueEval areaEvalX = createAreaEval(xValues);
    confirm(INTERCEPT, areaEvalX, areaEvalY, -24516534.39905822);
    // Excel 2010 gives -24516534.3990583
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.formula.eval.ValueEval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.