00001 package jpl.test;
00002
00003 import java.util.Map;
00004 import jpl.Atom;
00005 import jpl.Compound;
00006 import jpl.Integer;
00007 import jpl.JPL;
00008 import jpl.PrologException;
00009 import jpl.Query;
00010 import jpl.Term;
00011 import jpl.Util;
00012 import jpl.Variable;
00013 import jpl.fli.Prolog;
00014
00015
00016 public class TestOLD {
00017 private static void test10() {
00018 System.err.println("test10:");
00019 System.err.println(" java_lib_version = " + JPL.version_string());
00020 System.err.println(" c_lib_version = " + jpl.fli.Prolog.get_c_lib_version());
00021 System.err.println(" pl_lib_version = " + new Query(new Compound("jpl_pl_lib_version", new Term[] { new Variable("V") })).oneSolution().get("V"));
00022 System.err.println(" java.version = " + System.getProperty("java.version"));
00023 System.err.println(" os.name = " + System.getProperty("os.name"));
00024 System.err.println(" os.arch = " + System.getProperty("os.arch"));
00025 System.err.println(" os.version = " + System.getProperty("os.version"));
00026 System.err.println();
00027 }
00028 private static void test10j() {
00029 Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
00030 Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 }));
00031 Map[] s9s = q9.allSolutions();
00032 System.err.println("test10j:");
00033 for (int i = 0; i < s9s.length; i++) {
00034 System.err.println(" append(Xs,Ys,[a,b,c,d,e]) -> " + Util.toString(s9s[i]));
00035 }
00036 System.err.println();
00037 }
00038 private static void test10k() {
00039 String[] args = jpl.fli.Prolog.get_default_init_args();
00040 String which;
00041 String s = "";
00042 System.err.println("test10k:");
00043 if (args == null) {
00044 args = jpl.fli.Prolog.get_actual_init_args();
00045 which = "actual";
00046 } else {
00047 which = "default";
00048 }
00049 for (int i = 0; i < args.length; i++) {
00050 s = s + args[i] + " ";
00051 }
00052 System.err.println(" " + which + "_init_args = " + s + '\n');
00053 }
00054 private static void test10l() {
00055 Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new jpl.Integer(5) }));
00056 Map s5 = q5.oneSolution();
00057 System.err.println("test10l:");
00058 System.err.println(" length(Zs,5)");
00059 System.err.println(" " + Util.toString(s5));
00060 System.err.println(" Zs = " + (Term) s5.get("Zs"));
00061 System.err.println();
00062 }
00063 private static void test10m() {
00064 String text = "append(Xs,Ys,[_,_,_,_,_])";
00065 Query q = new Query(text);
00066 Map[] ss = q.allSolutions();
00067 System.err.println("test10m:");
00068 System.err.println(" all solutions of " + text);
00069 for (int i = 0; i < ss.length; i++) {
00070 System.err.println(" " + Util.toString(ss[i]));
00071 }
00072 System.err.println();
00073 }
00074 private static void test10o() {
00075 System.err.println("test10o:");
00076 Term l2b = Util.termArrayToList(new Term[] { new Variable("A"), new Variable("B"), new Variable("C"), new Variable("D"), new Variable("E") });
00077 Query q9b = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2b }));
00078 Map[] s9bs = q9b.allSolutions();
00079 for (int i = 0; i < s9bs.length; i++) {
00080 System.err.println(" append(Xs,Ys,[A,B,C,D,E]) -> " + Util.toString(s9bs[i]));
00081 }
00082 System.err.println();
00083 }
00084 private static void test10q() {
00085 System.err.println("test10q:");
00086 System.err.println((new Compound("Bad Name", new Term[] { new Atom("3 3") })).toString());
00087 System.err.println();
00088 }
00089 private static void test10s() {
00090 final Query q = new Query("jpl_slow_goal");
00091 System.err.println("test10s:");
00092 Thread t = new Thread(new Runnable() {
00093 public void run() {
00094 try {
00095 System.err.println("q.hasSolution() ... ");
00096 System.err.println(q.hasSolution() ? "finished" : "failed");
00097 } catch (Exception e) {
00098 System.err.println("q.hasSolution() threw " + e);
00099 }
00100 }
00101 });
00102 t.start();
00103 System.err.println("pausing for 2 secs...");
00104 try {
00105 Thread.sleep(2000);
00106 } catch (InterruptedException e) {
00107 ;
00108 }
00109
00110 System.err.println("calling q.abort()...");
00111 q.abort();
00112 System.err.println();
00113 }
00114 public static void main(String argv[]) {
00115 Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "none", "-g", "set_prolog_flag(debug_on_error,false)", "-q" });
00116 System.err.println("tag = " + Prolog.object_to_tag(new Query("hello")));
00117 test10k();
00118 test10();
00119
00120
00121 test10j();
00122 test10k();
00123 test10l();
00124 test10m();
00125
00126 test10o();
00127
00128 test10q();
00129
00130
00131
00132
00133
00134 String s = new String("" + '\0' + '\377');
00135 System.err.println("s.length = " + s.length());
00136 for (int i = 0; i < s.length(); i++) {
00137 System.err.print((new Integer(s.charAt(i))).toString() + " ");
00138 }
00139 System.err.println();
00140 System.err.println(new Query("atom_codes(A,[127,128,255,0])").oneSolution().toString());
00141 }
00142 }