use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.
the class TestJUnit method testEmptyParentheses.
// the tests; all public void test*()
// public void testInfo() {
// Term swi = Query.oneSolution("current_prolog_flag(version_data,Swi)").get("Swi");
// System.out.println("version = " + swi.arg(1) + "." + swi.arg(2) + "." + swi.arg(3));
// System.out.println("syntax = " + Query.oneSolution("jpl:jpl_pl_syntax(Syntax)").get("Syntax"));
// System.out.println("jpl.jar = " + JPL.version_string() + " " + JPL.jarPath());
// System.out.println("jpl.dll = " + Prolog.get_c_lib_version());
// System.out.println("jpl.pl = " + Query.oneSolution("jpl:jpl_pl_lib_version(V)").get("V").name() + " "
// + Query.oneSolution("module_property(jpl, file(F))").get("F").name());
// System.out.println("home = " + Query.oneSolution("current_prolog_flag(home,Home)").get("Home").name());
// }
public void testEmptyParentheses() {
// valid in both
Term t = Query.oneSolution("T = a()").get("T");
// traditional and
// modern syntax in SWI
// Prolog 7.x
assertTrue("T is not bound to an atom", t.isAtom());
assertTrue("the atom's name is not \"a\"", t.name().equals("a"));
}
use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.
the class TestJUnit method testJRef5.
public void testJRef5() {
String token = "foobar345";
Term a = Query.oneSolution("jpl_new('java.lang.StringBuffer',[?],A)", new Term[] { new Atom(token) }).get("A");
assertTrue(((java.lang.StringBuffer) (a.jrefToObject())).toString().equals(token));
}
use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.
the class TestJUnit method testOpenGetClose1.
public void testOpenGetClose1() {
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) {
sb.append(((Atom) soln.get("C")).name());
}
q.close();
assertEquals("prolog", sb.toString());
}
use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.
the class Test method test_11.
static void test_11() {
System.out.print("test 11...");
Term tuple = new Compound("t", new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
try {
Variable X = new Variable("X");
Query q11 = new Query("tuple", new Term[] { X });
Term result = q11.oneSolution().get("X");
if (result == null || !result.equals(tuple)) {
System.out.println("failed:");
System.out.println("\tresult: " + result);
System.out.println("\ttuple: " + tuple);
// System.exit(1);
}
if (result.arg(1) == null || !result.arg(1).equals(new Atom("a"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(1): " + result.arg(1));
// System.exit(1);
}
if (result.arg(2) == null || !result.arg(2).equals(new Atom("b"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(2): " + result.arg(2));
// System.exit(1);
}
if (result.arg(5) == null || !result.arg(5).equals(new Atom("e"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(5): " + result.arg(5));
// System.exit(1);
}
// arg0(6) throws an exception, as I'd expect it to...
// if ( ((Compound)result).arg( 7 ) != null ){
// System.out.println( "failed:" );
// System.out.println( "\t((Compound)result).arg( 7 ): " + ((Compound)result).arg( 7 ) );
// System.out.println( "\tshould be null" );
// System.exit( 1 );
// }
} catch (PrologException e) {
System.out.println("failed");
e.printStackTrace();
// System.exit(1);
}
System.out.println("passed");
}
use of org.jpl7.Atom in project packages-jpl by SWI-Prolog.
the class TestGC method main.
public static void main(String[] argv) {
int max;
Query.hasSolution("consult('test.pl')");
if (argv.length > 0)
max = Integer.parseInt(argv[0]);
else
max = 10;
System.out.println(max + " iterations");
for (int i = 0; i < max; i++) {
Query q = new Query("testpred", new Term[] { new Atom("a" + i) });
q.oneSolution();
}
Query.hasSolution("stats");
}
Aggregations