use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testVariableBinding4.
public void testVariableBinding4() {
Term lhs = new Compound("p", new Term[] { new Variable("_"), new Variable("_") });
Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
Term goal = new Compound("=", new Term[] { lhs, rhs });
assertTrue("two distinct anonymous Variables can unify with distinct atoms", new Query(goal).hasSolution());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testLength1.
public void testLength1() {
Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new org.jpl7.Integer(2) }));
Term zs = q5.oneSolution().get("Zs");
assertTrue("length(Zs,2) binds Zs to a list of two distinct variables " + zs.toString(), zs.isListPair() && zs.arg(1).isVariable() && zs.arg(2).isListPair() && zs.arg(2).arg(1).isVariable() && zs.arg(2).arg(2).isListNil() && !zs.arg(1).name().equals(zs.arg(2).arg(1).name()));
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testOpen1.
public void testOpen1() {
Query q = new Query("dummy");
assertTrue("a newly created query is not open", !q.isOpen());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testVariableBinding2.
public void testVariableBinding2() {
Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("X") });
Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
Term goal = new Compound("=", new Term[] { lhs, rhs });
assertFalse("two distinct Variables with same name cannot unify with distinct atoms", new Query(goal).hasSolution());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestOLD method test10s.
@SuppressWarnings("unused")
private static void test10s() {
// 10 successive sleep(1)
final Query q = new Query("jpl_slow_goal");
System.err.println("test10s:");
Thread t = new Thread(new Runnable() {
public void run() {
try {
System.err.println("q.hasSolution() ... ");
System.err.println(q.hasSolution() ? "finished" : "failed");
} catch (Exception e) {
System.err.println("q.hasSolution() threw " + e);
}
}
});
// call the query in a separate thread
t.start();
System.err.println("pausing for 2 secs...");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
;
}
// wait a coupla seconds for it to get started
// (new Query("set_prolog_flag(abort_with_exception,
// true)")).hasSolution();
System.err.println("calling q.abort()...");
// q.abort();
System.err.println();
}
Aggregations