Пример #1
0
 private void test(String exp) throws ScriptException {
   Expression el = factory.create(exp);
   Object jsv = se.eval(exp);
   Object elv = el.evaluate();
   // System.out.println(exp +":"+jsv);
   // System.out.println(":"+elv);
   // System.out.println(jsv.getClass());
   assertEquals(jsv, elv);
 }
Пример #2
0
  private void testLike(String exp, double max) throws ScriptException {
    Expression el = factory.create(exp);
    Number jsv = (Number) se.eval(exp);
    Number elv = (Number) el.evaluate();

    if (Double.isNaN(jsv.doubleValue()) != Double.isNaN(elv.doubleValue())) {
      Assert.fail("误差太大:" + exp + "\n" + jsv + "\n" + elv);
    }
    max *= Math.max(jsv.doubleValue(), elv.doubleValue());
    double offset = Math.abs(jsv.doubleValue() - elv.doubleValue());
    if (offset > max) {
      Assert.fail("误差太大了:" + exp + "\n" + jsv + "\n" + elv);
    }
  }