Esempio n. 1
0
        public async void ShouldFindNose()
        {
            // arrange
            var first = await inpy.Get();

            var second = await inpy.Get();

            // act
            var result = _cut.Compare(first, second);

            // assert
            result.Should().Be(1);
        }
        public async Task <Bitmap> CheckInput()
        {
            var input = await _inputProvider.Get();

            var hasChanged = _changeDetector.HasChanged(input);

            if (hasChanged)
            {
                return(input);
            }

            return(null);
        }
Esempio n. 3
0
        private void InitializeActionList(IInputProvider input, IOutputProvider output)
        {
            actions = new Dictionary<char, Action>();

            //Pointer manipulation
            actions.Add('>', () =>
            {
                PointerPosition++;

                //Allocate new memory cells as we go
                if (MemoryCells.Count <= PointerPosition)
                    MemoryCells.Add(0);
            });

            actions.Add('<', () =>
            {
                PointerPosition--;

                if (PointerPosition < 0)
                    PointerPosition = 0;
            });

            //Current cell manipulation
            actions.Add('+', () => MemoryCells[PointerPosition]++);
            actions.Add('-', () => MemoryCells[PointerPosition]--);

            //Input and output
            actions.Add(',', () => MemoryCells[PointerPosition] = Convert.ToInt32(input.Get()));
            actions.Add('.', () => output.Write(MemoryCells[PointerPosition].ToString()));

            actions.Add('[', () =>
            {
                loopIndexes.Push(currentProgramStringIndex);

                //Enter the loop if the current memory cell is different than zero
                if (MemoryCells[PointerPosition] != 0)
                    return;

                //Else we skip until the end of that loop
                do
                {
                    currentProgramStringIndex++;

                    //Stack-based logic in case we encounter any inner loops
                    if (ProgramString[currentProgramStringIndex] == '[')
                    {
                        loopIndexes.Push(currentProgramStringIndex);
                    }
                    else if (ProgramString[currentProgramStringIndex] == ']')
                    {
                        loopIndexes.Pop();
                    }
                //FIXME: Potential bug here if we are already in a loop
                } while (loopIndexes.Count > 0);
            });

            actions.Add(']', () =>
            {
                //Go back to the start of the loop
                if (MemoryCells[PointerPosition] != 0)
                    currentProgramStringIndex = loopIndexes.Peek();
                else
                    loopIndexes.Pop();
            });
        }