示例#1
0
        public void DoesBillLikeIcecream()
        {
            // likes (_, icecream).
            Compiled.Program program = EveryOneLikesIcecream();

            // ?- likes (bill, icecream).
            var goal = new AST.Goal
            {
                PredicateName = "likes",

                Arguments = new IArgument[]
                {
                    new Atom {
                        Name = "bill"
                    },
                    new Atom {
                        Name = "icecream"
                    }
                }
            };

            var solutions = Helper.Solve(goal, program);

            var solution = solutions.Single();        // a single solution means prolog says 'yes'

            Assert.IsFalse(solution.Variables.Any()); // no variables in query
        }
示例#2
0
        public void WhatDoesBillLike()
        {
            // likes (_, icecream).
            Compiled.Program program = EveryOneLikesIcecream();

            // ?- likes (bill, X).
            var goal = new AST.Goal
            {
                PredicateName = "likes",

                Arguments = new IArgument[]
                {
                    new Atom {
                        Name = "bill"
                    },
                    new Variable {
                        Name = "X"
                    }
                }
            };

            var solutions = Helper.GetSolutions(goal, program);

            var variables = solutions.Single();

            var variable = variables.Single();

            Assert.AreEqual("X", variable.Key);
            Assert.AreEqual("icecream", ((Runtime.Atom)variable.Value).Name);
        }
示例#3
0
        public void WhatDoesBillLike()
        {
            // likes (_, icecream).
            Compiled.Program program = EveryOneLikesIcecream ();

            // ?- likes (bill, X).
            var goal = new AST.Goal 
            {
                PredicateName = "likes",

                Arguments = new IArgument[]
                {
                    new Atom {Name = "bill"},
                    new Variable {Name = "X"}
                }
            };

            var solutions = Helper.GetSolutions (goal, program);

            var variables = solutions.Single();

            var variable = variables.Single();

            Assert.AreEqual ("X", variable.Key);
            Assert.AreEqual ("icecream", ((Runtime.Atom) variable.Value).Name);
        }
示例#4
0
        private static void AssertExternalPredicateSolutionIsCorrect(AST.Goal goal, Compiled.Program program)
        {
            var solutions = Helper.GetSolutions(goal, program);

            var variables = solutions.Single();

            Assert.AreEqual("john", ((Runtime.Atom)variables ["X"]).Name);
        }
示例#5
0
        public void IsJohnAnAnimal()
        {
            var database = MakeDogsDatabase();

            // ?- animal (john).
            var goal = new AST.Goal
            {
                PredicateName = "animal",

                Arguments = new IArgument[]
                {
                    new Atom {
                        Name = "john"
                    }
                }
            };

            var solutions = Helper.Solve(goal, database);

            Assert.IsFalse(solutions.Any());  // prolog says 'don't know'.
        }
示例#6
0
        public void DoesBillLikeIcecream()
        {
            // likes (_, icecream).
            Compiled.Program program = EveryOneLikesIcecream ();

            // ?- likes (bill, icecream).
            var goal = new AST.Goal 
            {
                PredicateName = "likes",

                Arguments = new IArgument[]
                {
                    new Atom {Name = "bill"},
                    new Atom {Name = "icecream"}
                }
            };

            var solutions = Helper.Solve (goal, program);

            var solution = solutions.Single(); // a single solution means prolog says 'yes'

            Assert.IsFalse (solution.Variables.Any()); // no variables in query
        }
示例#7
0
 public static IEnumerable <Runtime.ISolutionTreeNode> Solve(AST.Goal goal, Compiled.Program program)
 {
     return(Compiler.Solve(new Runtime.Engine(), new [] { goal }, program));
 }
示例#8
0
        public static IEnumerable <Dictionary <string, Runtime.IConcreteValue> > GetSolutions(AST.Goal goal, Compiled.Program program)
        {
            var solutions = Solve(goal, program);

            return(solutions.Select(GetTopLevelVariables));
        }
示例#9
0
        private static IEnumerable <Dictionary <string, Runtime.IConcreteValue> > CallConcat(AST.Goal makeGoal)
        {
            var program = Compiler.Compile(new AST.Program {
                ExternalPredicates = Helper.GetConcatDeclaration()
            });

            program.SetExternalPredicateCallbacks(Helper.GetConcat());

            return(Helper.GetSolutions(makeGoal, program));
        }
示例#10
0
        private static void AssertNoSolutions(AST.Goal goal)
        {
            var solutions = CallConcat(goal);

            Assert.IsFalse(solutions.Any());
        }
示例#11
0
        public void IsJohnAnAnimal()
        {
            var database = MakeDogsDatabase ();

            // ?- animal (john).
            var goal = new AST.Goal 
            {
                PredicateName = "animal",

                Arguments = new IArgument[]
                {
                    new Atom {Name = "john"}
                }
            };

            var solutions = Helper.Solve (goal, database);

            Assert.IsFalse (solutions.Any()); // prolog says 'don't know'.
        }