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 RunShouldMoveLeftCorrectly() { var program = new string('<', 2); var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); A.CallTo(() => _memoryMock.MoveLeft()).MustHaveHappened(Repeated.Exactly.Twice); }
private static void Main() { const string program = ">+[>,]<[<]>>[.>]"; const string input = "Hello\n\0"; var i = 0; Func<int> readFunc = () => input[i++]; Console.WriteLine(program); var runner = new BrainfuckRunner(new ArrayMemory(), program, readFunc, Console.Write); runner.Run(); }
private static void Main() { const string program = ">+[>,]<[<]>>[.>]"; const string input = "Hello\n\0"; var i = 0; Func <int> readFunc = () => input[i++]; Console.WriteLine(program); var runner = new BrainfuckRunner(new ArrayMemory(), program, readFunc, Console.Write); runner.Run(); }
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 RunShouldHandleSimpleLoopCorrectly() { const string program = "+++[-]."; var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction); runner.Run(); A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once); }
public void RunShouldPrintCharCorrectly() { var runner = new BrainfuckRunner(_memoryMock, ".", _readFunc, _writeAction); runner.Run(); A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once); }
public void RunShouldThrowExceptionForInvalidOperation() { var runner = new BrainfuckRunner(_memoryMock, "%", _readFunc, _writeAction); Assert.Throws<ArgumentException>(() => runner.Run()); }
public void RunShouldThrowExceptionForUnmatchedOpeningBracket() { // ReSharper disable once UnusedVariable var runner = new BrainfuckRunner(_memoryMock, "[+++", _readFunc, _writeAction); }
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); }