*/
@Test
public void testCall() throws Exception {
logger1.info("call");
BSFManager.registerScriptingEngine("jruby", "org.jruby.embed.bsf.JRubyEngine", new String[] {"rb"});
BSFManager manager = new BSFManager();
JRubyEngine instance = (JRubyEngine) manager.loadScriptingEngine("jruby");
instance.initialize(manager, "jruby", null);
Object recv = null;
String method = "";
Object[] args = null;
Object expResult = null;
Object result = instance.call(recv, method, args);
assertEquals(expResult, result);
String script =
"# Radioactive decay\n" +
"def amount_after_years(q0, t)\n" +
"q0 * Math.exp(1.0 / $h * Math.log(1.0/2.0) * t)\n" +
"end\n" +
"def years_to_amount(q0, q)\n" +
"$h * (Math.log(q) - Math.log(q0)) / Math.log(1.0/2.0)\n" +
"end";
recv = manager.eval("jruby", "radioactive_decay", 0, 0, script);
method = "amount_after_years";
args = new Object[2];
args[0] = 10.0; args[1] = 1000;
// Radium
manager.declareBean("h", 1599, Long.class);
result = instance.call(recv, method, args);
assertEquals(6.482, (Double)result, 0.001);
method = "years_to_amount";
args[0] = 10.0; args[1] = 1.0;