public void InstructionTableStoresAddedInstructions() { InstructionTable table = new InstructionTable(); Instruction instructionA = new Instruction(); instructionA.State = "A"; table.AddInstruction(instructionA); Assert.AreEqual(instructionA, table.GetInstruction(instructionA.State)); }
public void InstructionTableAddsToWriteSymbolsIf2InstructionsHaveTheSameState() { InstructionTable table = new InstructionTable(); Instruction instructionA1 = new Instruction(); instructionA1.State = "A"; instructionA1.WriteSymbols['0'] = '1'; Instruction instructionA2 = new Instruction(); instructionA2.State = "A"; instructionA2.WriteSymbols['1'] = '0'; table.AddInstruction(instructionA1); table.AddInstruction(instructionA2); Instruction storedInstruction = table.GetInstruction("A"); Assert.AreEqual(2, storedInstruction.WriteSymbols.Keys.Count); Assert.AreEqual('1', storedInstruction.WriteSymbols['0']); Assert.AreEqual('0', storedInstruction.WriteSymbols['1']); }
public void InstructionTableAddsToNextStatesIf2InstructionsHaveTheSameState() { InstructionTable table = new InstructionTable(); Instruction instructionA1 = new Instruction(); instructionA1.State = "A"; instructionA1.NextStates['0'] = "B"; Instruction instructionA2 = new Instruction(); instructionA2.State = "A"; instructionA2.NextStates['1'] = "C"; table.AddInstruction(instructionA1); table.AddInstruction(instructionA2); Instruction storedInstruction = table.GetInstruction("A"); Assert.AreEqual(2, storedInstruction.NextStates.Keys.Count); Assert.AreEqual("B", storedInstruction.NextStates['0']); Assert.AreEqual("C", storedInstruction.NextStates['1']); }
public void InstructionTableAddsToMoveDirectionsIf2InstructionsHaveTheSameState() { InstructionTable table = new InstructionTable(); Instruction instructionA1 = new Instruction(); instructionA1.State = "A"; instructionA1.MoveDirections['0'] = MoveDirection.Left; Instruction instructionA2 = new Instruction(); instructionA2.State = "A"; instructionA2.MoveDirections['1'] = MoveDirection.Right; table.AddInstruction(instructionA1); table.AddInstruction(instructionA2); Instruction storedInstruction = table.GetInstruction("A"); Assert.AreEqual(2, storedInstruction.MoveDirections.Keys.Count); Assert.AreEqual(MoveDirection.Left, storedInstruction.MoveDirections['0']); Assert.AreEqual(MoveDirection.Right, storedInstruction.MoveDirections['1']); }
public void InstructionTableThrowsExceptionOnNullInstructions() { InstructionTable table = new InstructionTable(); table.AddInstruction(null); }
private static IInstructionTable ParseInstructions(string[] args) { String filename = "./instructions.tbl"; if (args.Length >= 1) { filename = args[0]; } Console.Title = "Turing Machine - " + Path.GetFileNameWithoutExtension(filename); String[] instructionLines = File.ReadAllLines(filename); IInstructionTable table = new InstructionTable(); foreach (String instructionLine in instructionLines) { table.AddInstruction(InstructionParser.Parse(instructionLine)); } return table; }