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

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


  }

  public void testHeterogeneous() {

    ValueEval[] values = {
        new NumberEval(4),
        BoolEval.FALSE,
        new NumberEval(5),
        new StringEval("Albert"),
        BoolEval.FALSE,
        BoolEval.TRUE,
        new NumberEval(10),
        new StringEval("Charles"),
        new StringEval("Ed"),
        new NumberEval(10),
        new NumberEval(25),
        BoolEval.TRUE,
        new StringEval("Ed"),
    };

    AreaEval ae = EvalFactory.createAreaEval("A1:A13", values);

    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));

    confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
    confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));

    confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
        //wildcard values
        confirmInt(8, invokeMatch(new StringEval("CHAR*"), ae, MATCH_EXACT));
        confirmInt(8, invokeMatch(new StringEval("*CHARLES"), ae, MATCH_EXACT));

    confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));

    confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("ED*"), ae, MATCH_LARGEST_LTE));
    confirmInt(13, invokeMatch(new StringEval("*ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
    confirmInt(9, invokeMatch(new StringEval("ED*"), ae, MATCH_EXACT));

    confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));

    confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
    confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
  }
View Full Code Here


   * Bugzilla 44421
   */
  public void testMatchArgTypeArea() {

    ValueEval[] values = {
      new NumberEval(4),
      new NumberEval(5),
      new NumberEval(10),
      new NumberEval(10),
      new NumberEval(25),
    };

    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);

    AreaEval matchAE = EvalFactory.createAreaEval("C1:C1", new ValueEval[] { MATCH_LARGEST_LTE, });

    try {
      confirmInt(4, invokeMatch(new NumberEval(10), ae, matchAE));
    } catch (RuntimeException e) {
      if(e.getMessage().startsWith("Unexpected match_type type")) {
        // identified bug 44421
        fail(e.getMessage());
      }
View Full Code Here

  }

  public void testBasic() {
    Double exp = Math.pow(10, 7.5);
    ValueEval[] yValues = {
      new NumberEval(3+exp),
      new NumberEval(4+exp),
      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

  /**
   * number of items in array is not limited to 30
   */
  public void testLargeArrays() {
    ValueEval[] yValues = createMockNumberArray(100, 3); // [1,2,0,1,2,0,...,0,1]
    yValues[0] = new NumberEval(2.0); // Changes first element to 2
    ValueEval[] xValues = createMockNumberArray(100, 101); // [1,2,3,4,...,99,100]

    confirm(SLOPE, createAreaEval(xValues), createAreaEval(yValues), -1.231527093596059);
    // Excel 2010 gives -1.23152709359606
  }
View Full Code Here

  }

  private ValueEval[] createMockNumberArray(int size, double value) {
    ValueEval[] result = new ValueEval[size];
    for (int i = 0; i < result.length; i++) {
      result[i] = new NumberEval((i+1)%value);
    }
    return result;
  }
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);
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");
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());
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());
View Full Code Here

  }

  public void testBasic() {
    Double exp = Math.pow(10, 7.5);
    ValueEval[] yValues = {
      new NumberEval(3+exp),
      new NumberEval(4+exp),
      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.NumberEval

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.