Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void RunShouldHandleSimpleLoopCorrectly()
        {
            const string program = "+++[-].";
            var runner = new BrainfuckRunner(_memoryMock, program, _readFunc, _writeAction);

            runner.Run();

            A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 7
0
 public void RunShouldPrintCharCorrectly()
 {
     var runner = new BrainfuckRunner(_memoryMock, ".", _readFunc, _writeAction);
     runner.Run();
     A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once);
 }
Esempio n. 8
0
 public void RunShouldThrowExceptionForInvalidOperation()
 {
     var runner = new BrainfuckRunner(_memoryMock, "%", _readFunc, _writeAction);
     Assert.Throws<ArgumentException>(() => runner.Run());
 }
Esempio n. 9
0
 public void RunShouldThrowExceptionForUnmatchedOpeningBracket()
 {
     // ReSharper disable once UnusedVariable
     var runner = new BrainfuckRunner(_memoryMock, "[+++", _readFunc, _writeAction);
 }
Esempio n. 10
0
        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);
        }