public void AddLabel_4() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AddLabel("male/1", new ProgramClause("male", 1)); program.AddLabel("male/1", new ProgramClause("male", 1)); program.AddLabel("male/1", new ProgramClause("male", 1)); program.AddLabel("male/1", new ProgramClause("male", 1)); ProgramClause male1 = program["male/1"]; ProgramClause male2 = male1.NextPredicate; ProgramClause male3 = male2.NextPredicate; ProgramClause male4 = male3.NextPredicate; 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(), "retry_me_else"); Assert.AreEqual(male4.Name, "male%3/1"); Assert.AreEqual(male4.Arity, 1); Assert.AreEqual(male4.Instruction.Name(), "trust_me"); }
public AMInstructionSet() { _instructions["allocate"] = new AllocateInstruction(); _instructions["bcall"] = new BCallInstruction(); _instructions["call"] = new CallInstruction(); _instructions["cut"] = new CutInstruction(); _instructions["deallocate"] = new DeallocateInstruction(); _instructions["execute"] = new ExecuteInstruction(); _instructions["fcall"] = new FCallInstruction(); _instructions["fail"] = new FailInstruction(); _instructions["get_constant"] = new GetConstantInstruction(); _instructions["get_list"] = new GetListInstruction(); _instructions["get_structure"] = new GetStructureInstruction(); _instructions["get_value"] = new GetValueInstruction(); _instructions["get_variable"] = new GetVariableInstruction(); _instructions["halt"] = new HaltInstruction(); _instructions["nop"] = new NopInstruction(); _instructions["proceed"] = new ProceedInstruction(); _instructions["put_constant"] = new PutConstantInstruction(); _instructions["put_list"] = new PutListInstruction(); _instructions["put_structure"] = new PutStructureInstruction(); _instructions["put_unsafe_value"] = new PutUnsafeValueInstruction(); _instructions["put_variable"] = new PutVariableInstruction(); _instructions["put_value"] = new PutValueInstruction(); _instructions["retry_me_else"] = new RetryMeElseInstruction(); _instructions["set_constant"] = new SetConstantInstruction(); _instructions["set_local_value"] = new SetLocalValueInstruction(); _instructions["set_value"] = new SetValueInstruction(); _instructions["set_variable"] = new SetVariableInstruction(); _instructions["set_void"] = new SetVoidInstruction(); _instructions["trust_me"] = new TrustMeInstruction(); _instructions["try_me_else"] = new TryMeElseInstruction(); _instructions["unify_constant"] = new UnifyConstantInstruction(); _instructions["unify_local_value"] = new UnifyLocalValueInstruction(); _instructions["unify_variable"] = new UnifyVariableInstruction(); _instructions["unify_value"] = new UnifyValueInstruction(); _instructions["unify_void"] = new UnifyVoidInstruction(); _instructions["procedure"] = new ProcedureInstruction(); }
public void Program() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); Assert.AreSame(program.P.Instruction, program.Program.Instruction); }
public void AssertLast() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertLast("male", 1, p); program.AssertLast("male", 1, p); ProgramClause male1 = program["male/1"]; ProgramClause male2 = male1.NextPredicate; 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(), "trust_me"); }
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 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"); }