示例#1
0
 public void PlCallQuery3()
 {
     #region PlCallQuery_direct_3_doc
     PlTerm t = PlQuery.PlCallQuery("working_directory(O, O)");
     Assert.IsTrue(t.ToString().EndsWith("contrib-swiplcs/testswipl/bin/debug/"), "Path is not correct:" + t.ToString());
     #endregion PlCallQuery_direct_3_doc
 }
示例#2
0
        public void QueryPrologUnicode()
        {
            PlQuery.PlCall("consult('" + _plFilenameUtf8 + "')");
            PlTerm t = PlQuery.PlCallQuery("unicode(L)");

            Assert.AreEqual(StrUnicode, t.ToString());
        }
示例#3
0
        public void PlCallQuery0()
        {
            var t = PlQuery.PlCallQuery("member(A, [a,b,X])");

            Assert.IsTrue(t.IsAtom);
            Assert.AreEqual("a", t.ToString());
        }
示例#4
0
        public void QueryPrologAscii2()
        {
            PlQuery.PlCall("consult('" + _plFilenameUnicode + "')");
            PlTerm t = PlQuery.PlCallQuery("ascii(L)");

            Assert.AreEqual(StrAscii, t.ToString());
        }
示例#5
0
        public void QueryPrologLatin12()
        {
            PlQuery.PlCall("consult('" + _plFilenameUnicode + "')");
            PlTerm t = PlQuery.PlCallQuery("latin1(L)");

            Assert.AreEqual(StrLatin1, t.ToString());
        }
示例#6
0
 public void PlCallQuery2()
 {
     #region PlCallQuery_direct_2_doc
     PlTerm t = PlQuery.PlCallQuery("atom_concat(a, b, X)");
     Assert.AreEqual("ab", t.ToString());
     #endregion PlCallQuery_direct_2_doc
 }
示例#7
0
 //[TestMethod]
 public void StreamRead()
 {
     PlEngine.SetStreamReader(Sread);
     // NOTE: read/1 needs a dot ('.') at the end
     PlQuery.PlCall("assert( (test_read(A) :- read(A)) )");
     PlTerm t = PlQuery.PlCallQuery("test_read(A)");
     //     Assert.AreEqual(ref_string_read, t.ToString() + ".");
 }
示例#8
0
        public void list_sample2()
        {
            PlTerm list = PlQuery.PlCallQuery("sort([2,3,1,5,6], ListSorted)");

            foreach (PlTerm t in list)
            {
                Console.WriteLine(t.ToString());
            }
        }
示例#9
0
        public void StreamRead()
        {
            var rf = new DelegateStreamReadFunction(Sread);

            PlEngine.SetStreamFunctionRead(PlStreamType.Input, rf);
            // NOTE: read/1 needs a dot ('.') at the end
            PlQuery.PlCall("assert( (test_read(A) :- read(A)) )");
            PlTerm t = PlQuery.PlCallQuery("test_read(A)");

            Assert.AreEqual(ValidationStringRead, t.ToString() + ".");
        }
        public void t_creating_a_list()
        {
            Delegate d = new DelegateParameter1(create_list);

            PlEngine.RegisterForeign(d);
            for (int i = 1; i < 10; i++)
            {
                PlTerm t = PlQuery.PlCallQuery("create_list(L)");
                Assert.AreEqual("[a,b,c]", t.ToString(), "create_list failed!");
            }
        }
        public void t_modifying_a_list()
        {
            Delegate d = new DelegateParameter2(modify_list);

            PlEngine.RegisterForeign(d);
            for (int i = 1; i < 10; i++)
            {
                PlTerm t = PlQuery.PlCallQuery("modify_list([a,b,c], L)");
                Assert.AreEqual("[aa,bb,cc]", t.ToString(), "modify_list failed!");
            }
        }
        //[Ignore]
        //[TestMethod]
        public void t_backtrack()
        {
            Delegate d = new DelegateParameterBacktrack(my_member);

            PlEngine.RegisterForeign(d);
            for (int i = 1; i < 10; i++)
            {
                PlTerm t = PlQuery.PlCallQuery("my_member(X, [a,b,c])");
                Assert.AreEqual("abc", t.ToString(), "my_concat_atom failed!");
            }
        }
        public void t_varargs_single()
        {
// ReSharper disable once CSharpWarnings::CS0618
            Delegate d = new DelegateParameterVarArgs(my_concat_atom);

            PlEngine.RegisterForeign("my_concat_atom", 4, d);
            for (int i = 1; i < 10; i++)
            {
                PlTerm t = PlQuery.PlCallQuery("my_concat_atom(a,b,c, X)");
                Assert.AreEqual("abc", t.ToString(), "my_concat_atom failed!");
            }
        }
示例#14
0
 public void PlCallQuery1()
 {
     #region PlCallQuery_direct_1_doc
     PlTerm t = PlQuery.PlCallQuery("A = [a,b,c]");
     Assert.IsTrue(t.IsList);
     #endregion PlCallQuery_direct_1_doc
     int i = 0;
     foreach (PlTerm s in t)
     {
         Assert.AreEqual(_abc[i++], s.ToString());
     }
 }
        public void t_compound_term()
        {
            Delegate d = new DelegateParameter3(compound_term);

            PlEngine.RegisterForeign(d);
            PlTerm t = PlQuery.PlCallQuery("compound_term(test(P, schmerz, arm), 1, PART)");

            Assert.IsTrue(t.IsVar, "1 create_list failed!");
            t = PlQuery.PlCallQuery("compound_term(test(P, schmerz, arm), 2, PART)");
            Assert.AreEqual("schmerz", t.ToString(), "2 create_list failed!");
            t = PlQuery.PlCallQuery("compound_term(test(P, schmerz, arm), 3, PART)");
            Assert.AreEqual("arm", t.ToString(), "3 create_list failed!");
        }
        public void t_varargs()
        {
            Delegate d = new DelegateParameterVarArgs(my_concat_atom);

            PlEngine.RegisterForeign("my_concat_atom", 4, d);
            PlEngine.RegisterForeign("my_concat_atom", 7, d);
            for (int i = 1; i < 10; i++)
            {
                PlTerm t = PlQuery.PlCallQuery("my_concat_atom(a,b,c, X)");
                Assert.AreEqual("abc", t.ToString(), "my_concat_atom failed!");
                t = PlQuery.PlCallQuery("my_concat_atom(a,b,c,d,e,f, X)");
                Assert.AreEqual("abcdef", t.ToString(), "my_concat_atom failed!");
            }
        }
示例#17
0
        public void TestPlFrameSample()
        {
            var t1 = new PlTerm("dummy");

            AssertWord("test1");
            AssertWord("test2");
            var t2 = new PlTerm("dummy2");

            Assert.AreEqual(TermRefAccessor(t1), TermRefAccessor(t2) - 3);  // one per call of AssertWord

            PlQuery.PlCall("assert( (test(N) :- findall(X, word(X), L), length(L, N) ))");

            PlTerm term = PlQuery.PlCallQuery("test(N)");

            Assert.AreEqual(2, (int)term);
        }
        public static bool compound_term(PlTerm compound, PlTerm number, PlTerm l)
        {
            bool   isComp = compound.IsCompound;
            int    araty  = compound.Arity;
            string name   = compound.Name;

            System.Diagnostics.Debug.Print("compound_term {0} name={1} arity={2}", isComp, name, araty);

            using (new PlFrame())
            {
                PlTerm list = PlQuery.PlCallQuery(compound + " =.. L");

                // conversion is necessary because indexing the prolog list (list) is based on the
                // order of internal term references which might be *not* the order which we expect here.
                List <PlTerm> tl = Enumerable.ToList(list);

                l.Unify(tl[(int)number]);
            }

            return(true);
        }
示例#19
0
 public void PlCallQueryNoVariableException()
 {
     PlQuery.PlCallQuery("member(a, [a,b,c])");
 }
示例#20
0
 public void PlCallQueryTooMannyVariableException()
 {
     PlQuery.PlCallQuery("member(A, X)");
 }