Search in sources :

Example 21 with Term

use of org.jpl7.Term 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());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 22 with Term

use of org.jpl7.Term 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);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 23 with Term

use of org.jpl7.Term 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);
}
Also used : Query(org.jpl7.Query) TestSuite(junit.framework.TestSuite) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 24 with Term

use of org.jpl7.Term 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());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 25 with Term

use of org.jpl7.Term 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());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Aggregations

Term (org.jpl7.Term)62 Query (org.jpl7.Query)42 Variable (org.jpl7.Variable)24 Atom (org.jpl7.Atom)21 Compound (org.jpl7.Compound)21 Map (java.util.Map)12 BigInteger (java.math.BigInteger)6 Integer (org.jpl7.Integer)6 org.jpl7.fli.term_t (org.jpl7.fli.term_t)4 Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 PrologException (org.jpl7.PrologException)3 JPLException (org.jpl7.JPLException)2 IntHolder (org.jpl7.fli.IntHolder)2 URL (java.net.URL)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TestSuite (junit.framework.TestSuite)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1