public void ExecuteStep_NothingToExecute_Throws() { var sut = new ExecutionSnapshot <int>(new IInstruction <int> [0]); var context = CreateContext(InstructionExecutionCounter.Default); Assert.Throws <IllegalExecutionError>( () => sut.ExecuteStep(context)); }
public void ExecuteStep_ExecutionLimitReached_Throws() { var sut = new ExecutionSnapshot <int>(new IInstruction <int> [0]); var executionCounter = new InstructionExecutionCounter(5, 5); var context = CreateContext(executionCounter); Assert.Throws <ExecutionLimitReachedError>( () => sut.ExecuteStep(context)); }
public void AfterProgramExecution_BoardIsAsExpected() { var startState = string.Join(null, _startState); var currentState = _contextFactory.CreateInitialState(3, 3, startState, c => c); var instructions = _instructionFactory.CreateInstructionStack(Program); var snapshot = new ExecutionSnapshot <char>(instructions); var expectedState = string.Join(null, _expected); var expectedBoard = _contextFactory.CreateBoard(3, expectedState, EntryConverter); var verifier = new BoardVerifier <char>(expectedBoard, EntryComparer); while (!snapshot.ExecutionFinished(currentState)) { snapshot.ExecuteStep(currentState); } var result = verifier.Verify(currentState.Board); result.ShouldBeTrue(); }
public IEnumerable <ExecutionSnapshot> RecordExecution(byte[] program, int targetTime, IEnumerable <byte> pins) { //send an empty program uzi.runProgram(emptyProgram); System.Threading.Thread.Sleep(100); //wait for the mega to be ready string line = ""; while (line != "Ready. Waiting for target time\r") { line = mega.ReadLine(); } byte pinFlag = getPinFlag(pins); mega.Write(targetTime.ToString() + "," + pinFlag.ToString()); System.Threading.Thread.Sleep(100); uzi.runProgram(program); while (line != "Finished Capture\r") { line = mega.ReadLine(); } List <ExecutionSnapshot> result = new List <ExecutionSnapshot>(); line = mega.ReadLine(); while (line != "Ready. Waiting for target time\r") { var current = new ExecutionSnapshot(); var parts = line.Split(','); current.ms = int.Parse(parts[0]); byte pinData = byte.Parse(parts[1]); for (int j = 0; j < current.pins.Length; j++) { current.pins[j] = (byte)(pinData & 1); pinData = (byte)(pinData >> 1); } result.Add(current); line = mega.ReadLine(); } return(result); }