/** * Internals of testArithmetic which sets up a rule * and executes it with expected and illegal answers. */ private void doTestArithmetic(String op, int arg1, int arg2, int expected) { String rules = "[r1: (?x p ?a), (?x q ?b), (?x r ?c) " + op + "(?a, ?b, ?c) -> (?x s ?c)]\n " + "[r2: (?x p ?a), (?x q ?b), (?x t ?c) " + op + "(?a, ?b, ?c) -> (?x u ?c)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, Util.makeIntNode(arg1)) ); data.add(new Triple(n1, q, Util.makeIntNode(arg2)) ); data.add(new Triple(n1, r, Util.makeIntNode(expected)) ); data.add(new Triple(n1, t, Util.makeIntNode(expected+1)) ); InfGraph infgraph = createInfGraph(rules, data); assertTrue( infgraph.contains(n1, s, Util.makeIntNode(expected))); assertFalse( infgraph.contains(n1, u, Node.ANY) ); }
/** * Internals of testArithmetic which sets up a rule * and executes it with expected and illegal answers. */ private void doTestArithmetic(String op, int arg1, int arg2, int expected) { String rules = "[r1: (?x p ?a), (?x q ?b), (?x r ?c) " + op + "(?a, ?b, ?c) -> (?x s ?c)]\n " + "[r2: (?x p ?a), (?x q ?b), (?x t ?c) " + op + "(?a, ?b, ?c) -> (?x u ?c)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, Util.makeIntNode(arg1)) ); data.add(new Triple(n1, q, Util.makeIntNode(arg2)) ); data.add(new Triple(n1, r, Util.makeIntNode(expected)) ); data.add(new Triple(n1, t, Util.makeIntNode(expected+1)) ); InfGraph infgraph = createInfGraph(rules, data); assertTrue( infgraph.contains(n1, s, Util.makeIntNode(expected))); assertFalse( infgraph.contains(n1, u, Node.ANY) ); }
/** * Test recursive rules involving functors. * May lock up in there is a bug. * TODO: arrange test to run in a separate thread with a timeout */ public void doTestFunctorLooping(RuleMode mode) { Graph data = Factory.createGraphMem(); data.add(new Triple(a, r, b)); List<Rule> rules = Rule.parseRules( "(?x r ?y) -> (?x p func(?x)). (?x p ?y) -> (?x p func(?x))." ); GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(null); reasoner.setRules(rules); reasoner.setMode(mode); InfGraph infgraph = reasoner.bind(data); // The p should have been asserted but is invisible assertFalse( infgraph.contains(Node.ANY, p, Node.ANY) ); }
/** * Test recursive rules involving functors. * May lock up in there is a bug. * TODO: arrange test to run in a separate thread with a timeout */ public void doTestFunctorLooping(RuleMode mode) { Graph data = Factory.createGraphMem(); data.add(new Triple(a, r, b)); List<Rule> rules = Rule.parseRules( "(?x r ?y) -> (?x p func(?x)). (?x p ?y) -> (?x p func(?x))." ); GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(null); reasoner.setRules(rules); reasoner.setMode(mode); InfGraph infgraph = reasoner.bind(data); // The p should have been asserted but is invisible assertFalse( infgraph.contains(Node.ANY, p, Node.ANY) ); }