use of org.apache.jena.sparql.expr.nodevalue.NodeValueDouble in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_06.
@Test
public void test_function_expansion_06() {
Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
ExprList numArgs = new ExprList();
numArgs.add(new NodeValueInteger(1));
numArgs.add(new NodeValueDouble(2.3));
Expr test = new E_Function("http://example/takeaway", numArgs);
UserDefinedFunctionFactory.getFactory().add("http://example/test", test, new ArrayList<Var>());
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/test");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Subtract);
E_Subtract subtract = (E_Subtract) base;
Assert.assertTrue(subtract.getArg1() instanceof NodeValueInteger);
Assert.assertTrue(subtract.getArg2() instanceof NodeValueDouble);
}
use of org.apache.jena.sparql.expr.nodevalue.NodeValueDouble in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_07.
@Test
public void test_function_expansion_07() {
Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
ExprList numArgs = new ExprList();
numArgs.add(new NodeValueDouble(2.3));
numArgs.add(new NodeValueInteger(1));
Expr test = new E_Function("http://example/takeaway", numArgs);
UserDefinedFunctionFactory.getFactory().add("http://example/test", test, new ArrayList<Var>());
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/test");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Subtract);
E_Subtract subtract = (E_Subtract) base;
Assert.assertTrue(subtract.getArg1() instanceof NodeValueDouble);
Assert.assertTrue(subtract.getArg2() instanceof NodeValueInteger);
}
Aggregations