use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class Query method get1.
private final boolean get1() {
// close the query;
if (Prolog.next_solution(qid)) {
return true;
} else {
// if failure was due to throw/1, build exception term and
// throw it
term_t exception_term_t = Prolog.exception(qid);
if (exception_term_t.value != 0L) {
Term exception_term = Term.getTerm(new HashMap<term_t, Variable>(), exception_term_t);
close();
throw new PrologException(exception_term);
} else {
close();
return false;
}
}
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testGetSolution1.
public void testGetSolution1() {
Query q = new Query("fail");
q.open();
q.getSolution();
assertTrue("an opened query on which getSolution has failed once is closed", !q.isOpen());
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testDontTellMeMode1.
public void testDontTellMeMode1() {
final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)");
JPL.setDTMMode(true);
assertTrue("in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for just one variable", q.oneSolution().keySet().size() == 1);
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testJRef2.
public void testJRef2() {
int i = 76543;
Integer I = new Integer(i);
Query q = new Query("jpl_call(?,intValue,[],I2)", JPL.newJRef(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 testWouter1.
public void testWouter1() {
// Wouter says this fails under OS X Mavericks
// 10.9 x86-64
// too big for an int
long n = 7381783232223l;
Compound term = new Compound("is", new Term[] { new Variable("X"), new org.jpl7.Integer(n) });
Map<String, Term>[] solutions = new Query(term).allSolutions();
assertEquals(1, solutions.length);
Map<String, Term> solution = solutions[0];
assertTrue(solution.containsKey("X"));
Object result = solution.get("X");
assertTrue(result instanceof org.jpl7.Integer);
assertEquals(n, ((org.jpl7.Integer) result).longValue());
}
Aggregations