Provides an interface to implement builtin predicates.
Inheritance: IAbstractMachinePredicate
コード例 #1
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void atom_1_list()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new AtomPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ListTerm());

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("atom", 1);
            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
コード例 #2
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void var_1_unbound()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new VarPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("var", 1);
            _p.Execute(state);

            Assert.AreNotSame(nextClause, program.P);
        }
コード例 #3
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void write_1()
        {
            AbstractMachineState state = SetupMachine();

            _p = new WritePredicate();

            Verify("write", 1);

            _p.Execute(state);
        }
コード例 #4
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void string_1_string()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new CharPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ConstantTerm("a"));

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("char", 1);
            _p.Execute(state);

            Assert.AreNotSame(nextClause, program.P);
        }
コード例 #5
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void unify_2()
        {
            AbstractMachineState state = SetupMachine();

            _p = new UnifyPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];

            X1.Assign(new ConstantTerm("ali"));

            Verify("=", 2);

            _p.Execute(state);

            Assert.AreEqual(X0.Data(), X1.Data());
            Assert.AreEqual("ali", X0.Data());
        }
コード例 #6
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void put_1()
        {
            AbstractMachineState state = SetupMachine();

            _p = new PutPredicate();

            AbstractTerm x0 = (AbstractTerm)state["X0"];

            x0.Assign(new ConstantTerm("61"));

            Verify("put", 1);

            _p.Execute(state);
        }
コード例 #7
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void skip_1()
        {
            AbstractMachineState state = SetupMachine();

            _p = new SkipPredicate();

            Verify("skip", 1);

            _p.Execute(state);
        }
コード例 #8
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void notunifiable_2()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new NotUnifiablePredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];

            X0.Assign(new ConstantTerm("ali"));
            X1.Assign(new ConstantTerm("ali"));

            Choicepoint b = new Choicepoint();

            ProgramClause nextClause = new ProgramClause();

            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);
            Verify("\\=", 2);

            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
コード例 #9
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void nl_0()
        {
            AbstractMachineState state = SetupMachine();

            _p = new NlPredicate();

            Verify("nl", 0);

            _p.Execute(state);
        }
コード例 #10
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void lessthan_2()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new LessThanPredicate();

            Verify("<", 2);

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];

            Choicepoint b = new Choicepoint();

            ProgramClause nextClause = new ProgramClause();

            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            X0.Assign(new ConstantTerm("5"));
            X1.Assign(new ConstantTerm("1"));

            // X0 < X1
            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
コード例 #11
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void get0_1()
        {
            AbstractMachineState state = SetupMachine();

            _p = new Get0Predicate();

            Verify("get0", 1);

            _p.Execute(state);
        }
コード例 #12
0
ファイル: BuiltinTests.cs プロジェクト: ahodroj/prologdotnet
        public void call_1()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new CallPredicate();

            Verify("call", 1);

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            StructureTerm goal = new StructureTerm("male", 1);
            goal.Next = new ConstantTerm("ali");
            program.AddLabel("male/1", new ProgramClause("male", 1));

            X0.Assign(goal);

            _p.Execute(state);

            Assert.AreEqual(X0.Data(), "ali");
            ProgramClause p = (ProgramClause)program.P;
            Assert.AreEqual(p.Name, "male");
            Assert.AreEqual(p.Arity, 1);
        }