use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testVariableBinding3.
public void testVariableBinding3() {
Variable X = new Variable("X");
Term lhs = new Compound("p", new Term[] { X, X });
Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
Term goal = new Compound("=", new Term[] { lhs, rhs });
assertFalse("two references to the same (named) Variable cannot unify with differing atoms", new Query(goal).hasSolution());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testArrayToList1.
public void testArrayToList1() {
Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 }));
assertTrue("append(Xs,Ys,[a,b,c,d,e]) has 6 solutions", q9.allSolutions().length == 6);
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testDontTellMeMode2.
public void testDontTellMeMode2() {
final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)");
JPL.setDTMMode(false);
assertTrue("not in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for three variables", q.oneSolution().keySet().size() == 3);
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testOpenGetClose2.
public void testOpenGetClose2() {
// we're not going to open this...
Query q = new Query("dummy");
try {
// should throw exception (query not open)
q.getSolution();
// shouldn't get
fail("getSolution() succeeds on unopened Query");
// to here
} catch (JPLException e) {
// expected exception class
if (e.getMessage().endsWith("Query is not open")) {
// OK: an appropriate exception was thrown
} else {
fail("jpl.Query#getSolution() threw wrong JPLException: " + e);
}
} catch (Exception e) {
fail("jpl.Query#getSolution() threw wrong exception class: " + e);
}
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testVariableBinding5.
public void testVariableBinding5() {
Variable Anon = new Variable("_");
Term lhs = new Compound("p", new Term[] { Anon, Anon });
Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
Term goal = new Compound("=", new Term[] { lhs, rhs });
assertTrue("two references to an anonymous Variable can unify with differing atoms", new Query(goal).hasSolution());
}
Aggregations