예제 #1
0
        public void RunShouldPrintCharCorrectly()
        {
            var runner = new BrainfuckRunner(_memoryMock, ".", _readFunc, _writeAction);

            runner.Run();
            A.CallTo(() => _writeAction('\0')).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #2
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);
        }
예제 #3
0
        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);
        }
예제 #4
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));
        }
예제 #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);
        }
예제 #6
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);
        }
예제 #7
0
        public void RunShouldThrowExceptionForInvalidOperation()
        {
            var runner = new BrainfuckRunner(_memoryMock, "%", _readFunc, _writeAction);

            Assert.Throws <ArgumentException>(() => runner.Run());
        }