public void RunShouldPrintCharCorrectly() { var runner = new BrainfuckRunner(_memoryMock, ".", _readFunc, _writeAction); runner.Run(); A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once); }
public void RunShouldHandleSimpleLoopCorrectly() { const string program = "+++[-]."; var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once); }
public void RunShouldMoveRightCorrectly() { var program = new string('>', 2); var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); A.CallTo(() => _memoryMock.MoveRight()).MustHaveHappened(Repeated.Exactly.Twice); }
public void RunShouldDecrementCorrectly() { var program = new string('-', 191); var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); A.CallTo(() => _memoryMock.Decrement()).MustHaveHappened(Repeated.Exactly.Times(191)); }
public void RunShouldReadCharCorrectly() { const string program = ","; var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); A.CallTo(() => _readFunc()).Returns('A'); runner.Run(); A.CallTo(() => _readFunc()).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(_memoryMock) .Where(call => call.Method.Name == "set_CurrentValue" && call.Arguments.Get <byte>(0) == 'A') .MustHaveHappened(Repeated.Exactly.Once); }
public void RunShouldHandleInnerLoopsCorrectly(string program) { var currentPosition = 0; var array = new byte[30000]; A.CallTo(() => _memoryMock.Increment()).Invokes(() => ++ array[currentPosition]); A.CallTo(() => _memoryMock.CurrentValue).ReturnsLazily(() => array[currentPosition]); A.CallTo(() => _memoryMock.MoveRight()).Invokes(() => currentPosition = (currentPosition + 1) % 3000); var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); Assert.AreEqual(0, _memoryMock.CurrentValue); }
public void RunShouldThrowExceptionForInvalidOperation() { var runner = new BrainfuckRunner(_memoryMock, "%", _readFunc, _writeAction); Assert.Throws <ArgumentException>(() => runner.Run()); }