public void Arity() { Choicepoint c = new Choicepoint(); c.Arity = 4; Assert.AreEqual(4, c.Arity); }
public void B() { Choicepoint c = new Choicepoint(); Choicepoint b = new Choicepoint(); c.B = b; Assert.AreSame(b, c.B); }
public void CP() { Choicepoint c = new Choicepoint(); ProgramNode cp = new ProgramNode(); c.CP = cp; Assert.AreSame(cp, c.CP); }
public void Create() { Choicepoint c = new Choicepoint(); Assert.IsNull(c.B); Assert.IsNull(c.CE); Assert.IsNull(c.CP); Assert.IsNull(c.H); Assert.IsNull(c.NextClause); }
public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, Choicepoint b0, int size) { _ce = ce; _cp = cp; _b0 = b0; for (int i = 0; i < size; i++) { AddVariable(); } }
public void CE() { Choicepoint c = new Choicepoint(); EnvironmentFrame ce = new EnvironmentFrame(); c.CE = ce; Assert.AreSame(ce, c.CE); }
public Choicepoint(int arity, EnvironmentFrame ce, ProgramNode cp, Choicepoint b, ProgramClause nextClause, int tr, HeapNode h) { _arity = arity; _ce = ce; _cp = cp; _b = b; _nextClause = nextClause; _tr = tr; _h = h; }
public void Custom() { HeapNode h = new HeapNode(); EnvironmentFrame ce = new EnvironmentFrame(); ProgramClause clause = new ProgramClause(); Choicepoint b = new Choicepoint(); ProgramNode cp = new ProgramNode(); Choicepoint c = new Choicepoint(2, ce, cp, b, clause, 3, h); Assert.AreSame(h, c.H); Assert.AreEqual(2, c.Arity); Assert.AreSame(ce, c.CE); Assert.AreSame(cp, c.CP); Assert.AreSame(b, c.B); Assert.AreSame(clause, c.NextClause); Assert.AreEqual(3, c.TR); }
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); }
public void TrustMe() { AbstractMachineState state = SetupMachine(); TrustMeInstruction i = new TrustMeInstruction(); i.Process(null); AMProgram program = (AMProgram)state.Program; AMTrail trail = (AMTrail)state.Trail; Choicepoint b = new Choicepoint(); b.CE = new EnvironmentFrame(); Choicepoint old = new Choicepoint(); b.B = old; b.CP = new ProgramNode(); b.TR = 1; b.NextClause = new ProgramClause(); state.B = b; i.Execute(state); Assert.AreEqual("trust_me", i.Name()); Assert.AreEqual(0, i.NumberOfArguments()); Assert.AreSame(state.E, b.CE); Assert.AreSame(program.CP, b.CP); Assert.AreEqual(b.TR, trail.TR); Assert.AreSame(state.B, old); }
public void RetryMeElse() { AbstractMachineState state = SetupMachine(); RetryMeElseInstruction i = new RetryMeElseInstruction(); AMProgram program = (AMProgram)state.Program; AMTrail trail = (AMTrail)state.Trail; Choicepoint b = new Choicepoint(); b.CE = new EnvironmentFrame(); b.B = new Choicepoint(); b.CP = new ProgramNode(); b.TR = 1; b.NextClause = new ProgramClause(); state.B = b; program.AddLabel("foobar/2", new ProgramClause()); object[] args = { "foobar/2" }; i.Process(args); i.Execute(state); Assert.AreEqual("retry_me_else", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); Assert.AreSame(state.E, b.CE); Assert.AreEqual(b.TR, trail.TR); Assert.AreEqual(state.B.NextClause, program["foobar/2"]); }
public void Cut() { AbstractMachineState state = SetupMachine(); Choicepoint old = new Choicepoint(); state.E = new EnvironmentFrame(null, null, old, 0); CutInstruction i = new CutInstruction(); i.Process(null); i.Execute(state); Assert.AreEqual("cut", i.Name()); Assert.AreEqual(0, i.NumberOfArguments()); Assert.AreSame(state.B, old); }
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); }
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); }
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); }
public void Indexing() { Choicepoint c = new Choicepoint(); Assert.IsNull(c["Y5"]); }
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); }
public void NextClause() { Choicepoint c = new Choicepoint(); ProgramClause clause = new ProgramClause(); c.NextClause = clause; Assert.AreSame(clause, c.NextClause); }
public void H() { Choicepoint c = new Choicepoint(); HeapNode h = new HeapNode(); c.H = h; Assert.AreSame(h, c.H); }
public void SaveRegisters() { AbstractMachineState state = new AbstractMachineState(new AMFactory()); ArrayList prog = new ArrayList(); prog.Add(new HaltInstruction()); state.Initialize(prog); AbstractTerm X0 = (AbstractTerm)state["X0"]; AbstractTerm X1 = (AbstractTerm)state["X1"]; AbstractTerm X2 = (AbstractTerm)state["X2"]; X0.Assign(new ConstantTerm("ali")); X1.Assign(new ConstantTerm("samir")); X2.Assign(new ConstantTerm("moe")); Choicepoint c = new Choicepoint(); c.SaveRegisters(state, 3); Assert.AreEqual("ali", c["X0"].Data()); Assert.AreEqual("samir", c["X1"].Data()); Assert.AreEqual("moe", c["X2"].Data()); }
public void SaveVariable() { Choicepoint c = new Choicepoint(); AbstractTerm term = new AbstractTerm(); c.SaveVariable(term); Assert.AreSame(c["X0"], term); c["X0"].Assign(new ConstantTerm("ali")); Assert.AreEqual("ali", c["X0"].Data()); }
public void TR() { Choicepoint c = new Choicepoint(); c.TR = 1; Assert.AreEqual(1, c.TR); }