コード例 #1
0
  @Test
  public void invokeMethod() throws ScriptException, NoSuchMethodException {
    Object obj = engine.eval("list(execute=sqrt)");
    DoubleVector result = (DoubleVector) invocableEngine.invokeMethod(obj, "execute", 16);

    assertThat(result.length(), equalTo(1));
    assertThat(result.get(0), equalTo(4d));
  }
コード例 #2
0
  @Test
  public void invokeFunction() throws ScriptException, NoSuchMethodException {
    engine.eval("f <- function(x) sqrt(x)");
    DoubleVector result = (DoubleVector) invocableEngine.invokeFunction("f", 4);

    assertThat(result.length(), equalTo(1));
    assertThat(result.get(0), equalTo(2d));
  }