コード例 #1
0
 public static IInstruction Create(char instruction, TapeMemory tapeMemory, BrainmessProgram program)
 {
     IInstruction iInstruction = null;
     switch (instruction)
     {
         case '>':
             iInstruction = new ForwardInstruction(tapeMemory, program);
             break;
         case '<':
             iInstruction = new BackwardInstruction(tapeMemory, program);
             break;
         case '+':
             iInstruction = new IncreamentInstruction(tapeMemory, program);
             break;
         case '-':
             iInstruction = new DecreamentInstruction(tapeMemory, program);
             break;
         case '.':
             iInstruction = new OutputInstruction(tapeMemory, program);
             break;
         case ',':
             iInstruction = new InputInstruction(tapeMemory, program);
             break;
         case '[':
             iInstruction = new LoopForwardInstruction(tapeMemory, program);
             break;
         case ']':
             iInstruction = new LoopBackwardInstruction(tapeMemory, program);
             break;
     }
     return iInstruction;
 }
コード例 #2
0
        public void TestLoopBackwardInstruction()
        {           
            var loopBackwardInstruction = new LoopBackwardInstruction
              (
                  new TapeMemory(),
                  new BrainmessProgram
                  {
                      Instructions = "--[++++]",
                      InstructionPointer = 5
                  }
              ) {TapeMemory = {CurrentCellValue = 1}};

            loopBackwardInstruction.Execute();
            Assert.AreEqual(2, loopBackwardInstruction.Program.InstructionPointer);
        }