Search in sources :

Example 66 with Term

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

the class TestJUnit method testVariableBinding3.

public void testVariableBinding3() {
    Variable X = new Variable("X");
    Term lhs = new Compound("p", new Term[] { X, X });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertFalse("two references to the same (named) Variable cannot unify with differing atoms", new Query(goal).hasSolution());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 67 with Term

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

the class TestJUnit method testArrayToList1.

public void testArrayToList1() {
    Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
    Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 }));
    assertTrue("append(Xs,Ys,[a,b,c,d,e]) has 6 solutions", q9.allSolutions().length == 6);
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 68 with Term

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

the class TestJUnit method testRef7.

public void testRef7() {
    Term badJRef = new Compound("@", new Term[] { new Atom("foobar") });
    try {
        // should throw exception
        badJRef.jrefToObject();
        // shouldn't
        fail("@(foobar) .jrefToObject() shoulda thrown JPLException");
    // get
    // to
    // here
    } catch (JPLException e) {
        // expected exception class
        if (e.getMessage().endsWith("term is not a JRef")) {
        // OK: an appropriate exception was thrown
        } else {
            fail("@(foobar) .jrefToObject() threw wrong JPLException: " + e);
        }
    } catch (Exception e) {
        fail("@(foobar) .jrefToObject() threw wrong exception class: " + e);
    }
}
Also used : JPLException(org.jpl7.JPLException) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Example 69 with Term

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

the class TestJUnit method testRef6.

public void testRef6() {
    Term nullJRef = new Compound("@", new Term[] { new Atom("null") });
    Object nullObject = nullJRef.jrefToObject();
    assertNull("@(null) .jrefToObject() yields null", nullObject);
}
Also used : Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 70 with Term

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

the class TestJUnit method testVariableBinding5.

public void testVariableBinding5() {
    Variable Anon = new Variable("_");
    Term lhs = new Compound("p", new Term[] { Anon, Anon });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertTrue("two references to an anonymous Variable can unify with differing atoms", new Query(goal).hasSolution());
}
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