public void AssertFirst_2() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause oldFirst = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause newFirst = program["male/1"]; Assert.AreEqual(newFirst.Name, "male"); Assert.AreEqual(newFirst.Arity, 1); Assert.AreEqual(newFirst.Instruction.Name(), "try_me_else"); Assert.AreEqual(oldFirst.Name, "male%1/1"); Assert.AreEqual(oldFirst.Arity, 1); Assert.AreEqual(oldFirst.Instruction.Name(), "trust_me"); }
public void Call() { ArrayList prog = new ArrayList(); prog.Add(new NopInstruction()); prog.Add(new HaltInstruction()); AbstractMachineState state = new AbstractMachineState(new AMFactory()); state.Initialize(prog); AMProgram program = (AMProgram)state.Program; ArrayList predicateCode = new ArrayList(); AMInstructionSet iset = new AMInstructionSet(); // say_hello(X) :- write(X). predicateCode.Add(iset.CreateInstruction("bcall", "write/1")); predicateCode.Add(iset.CreateInstruction("proceed")); AbstractTerm X0 = (AbstractTerm)state["X0"]; X0.Assign(new ConstantTerm("Hello, World!")); program.AssertFirst("say_hello", 1, predicateCode); Assert.IsTrue(state.Call("say_hello", 1, new object[] { "Hello man" })); }
public void AssertFirst_3() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause male3 = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause male2 = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause male1 = program["male/1"]; Assert.AreEqual(male1.Name, "male"); Assert.AreEqual(male1.Arity, 1); Assert.AreEqual(male1.Instruction.Name(), "try_me_else"); Assert.AreEqual(male2.Name, "male%1/1"); Assert.AreEqual(male2.Arity, 1); Assert.AreEqual(male2.Instruction.Name(), "retry_me_else"); Assert.AreEqual(male3.Name, "male%2/1"); Assert.AreEqual(male3.Arity, 1); Assert.AreEqual(male3.Instruction.Name(), "trust_me"); }
public void AssertFirst_1() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause male1 = program["male/1"]; Assert.AreEqual(male1.Name, "male"); Assert.AreEqual(male1.Arity, 1); Assert.AreEqual(male1.Instruction.Name(), "nop"); }