use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testHasMoreSolutions1.
public void testHasMoreSolutions1() {
StringBuffer sb = new StringBuffer();
Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
Map<String, Term> soln;
q.open();
while (q.hasMoreSolutions()) {
soln = q.nextSolution();
sb.append(((Atom) soln.get("C")).name());
}
q.close();
assertEquals("Query#hasMoreSolutions() + Query#nextSolution() work as intended", "prolog", sb.toString());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testJRef1.
public void testJRef1() {
int i = 76543;
Integer I = new Integer(i);
Query q = new Query("jpl_call(?,intValue,[],I2)", new Term[] { Term.objectToJRef(I) });
Term I2 = q.oneSolution().get("I2");
assertTrue(I2.isInteger() && I2.intValue() == i);
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method suite.
public static junit.framework.Test suite() {
if (syntax.equals("traditional")) {
JPL.setTraditional();
Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "--traditional", "-q", "--home=../..", "--nosignals" });
} else {
Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "-q", "--home=../..", "--nosignals" });
}
assertTrue((new Query("consult", new Term[] { new Atom(test_jpl) })).hasSolution());
assertTrue((new Query("use_module(library(jpl))")).hasSolution());
return new TestSuite(TestJUnit.class);
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testStackedQueries1.
public void testStackedQueries1() {
StringBuffer sb = new StringBuffer();
Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
Map<String, Term> soln;
q.open();
while ((soln = q.getSolution()) != null) {
Atom a = (Atom) soln.get("C");
if (Query.hasSolution("memberchk(?, [l,o,r])", new Term[] { a })) {
// this
// query
// opens
// and
// closes
// while
// an
// earlier
// query
// is
// still
// open
sb.append(((Atom) soln.get("C")).name());
}
}
// q will have been closed by the final
assertTrue(!q.isOpen());
// getSolution()
assertEquals("rolo", sb.toString());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testIsJNull1.
public void testIsJNull1() {
Term atNull = new Compound("@", new Term[] { new Atom("null") });
Query q = new Query("=", new Term[] { new Variable("X"), atNull });
assertTrue(q.oneSolution().get("X").isJNull());
}
Aggregations