Search in sources :

Example 6 with Atom

use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.

the class TestJUnit method testAtomName2.

public void testAtomName2() {
    String name = "ha ha";
    Atom a = new Atom(name);
    assertEquals("an Atom's name is that with which it was created", a.name(), name);
}
Also used : Atom(org.jpl7.Atom)

Example 7 with Atom

use of org.jpl7.Atom 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 8 with Atom

use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.

the class TestJUnit method testAtomName3.

public void testAtomName3() {
    String name = "3";
    Atom a = new Atom(name);
    assertEquals("an Atom's name is that with which it was created", a.name(), name);
}
Also used : Atom(org.jpl7.Atom)

Example 9 with Atom

use of org.jpl7.Atom 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 10 with Atom

use of org.jpl7.Atom 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)

Aggregations

Atom (org.jpl7.Atom)32 Term (org.jpl7.Term)23 Query (org.jpl7.Query)19 Compound (org.jpl7.Compound)13 Variable (org.jpl7.Variable)12 Map (java.util.Map)2 PrologException (org.jpl7.PrologException)2 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 TestSuite (junit.framework.TestSuite)1 JPLException (org.jpl7.JPLException)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 IntHolder (org.jpl7.fli.IntHolder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1 StringHolder (org.jpl7.fli.StringHolder)1 org.jpl7.fli.term_t (org.jpl7.fli.term_t)1