Assert.assertEquals(1, base.getVarsMentioned().size());
}
@Test
public void test_function_non_expansion_02() {
Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
//This test illustrates that if we change the definition of square and call our function again we can
//get a different result with dependencies preserved because the definition of the dependent function can change
Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
UserDefinedFunction f = (UserDefinedFunction) UserDefinedFunctionFactory.getFactory().create("http://example/cube");
f.build("http://example/cube", new ExprList(new NodeValueInteger(2)));
Expr actual = f.getActualExpr();
NodeValue result = actual.eval(BindingFactory.create(), FunctionEnvBase.createTest());
Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode()));
//Change the definition of the function we depend on
square = new ExprVar("x");
UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
f.build("http://example/cube", new ExprList(new NodeValueInteger(2)));
actual = f.getActualExpr();
result = actual.eval(BindingFactory.create(), FunctionEnvBase.createTest());
Assert.assertEquals(4, NodeFactoryExtra.nodeToInt(result.asNode()));
}