Ejemplo n.º 1
0
        public static bool TryParse(string input, out BootCommand command, out int argument)
        {
            var inputSplit = input.Split(' ');

            if (inputSplit.Length != 2)
            {
                command  = default;
                argument = default;
                return(false);
            }

            switch (inputSplit[0].ToLowerInvariant())
            {
            case "acc":
                command = BootCommand.Accumulate;
                break;

            case "jmp":
                command = BootCommand.Jump;
                break;

            case "nop":
                command = BootCommand.NoOperation;
                break;

            default:
                command  = default;
                argument = default;
                return(false);
            }

            return(int.TryParse(inputSplit[1], out argument));
        }
Ejemplo n.º 2
0
 public When_parsing_inputs(BootCommand command, int argument, int positionExpected, int accumulatorExpected)
 {
     _command             = command;
     _argument            = argument;
     _positionExpected    = positionExpected;
     _accumulatorExpected = accumulatorExpected;
 }
Ejemplo n.º 3
0
 public When_parsing_inputs(string input, bool result, BootCommand command, int argument)
 {
     _input    = input;
     _result   = result;
     _command  = command;
     _argument = argument;
 }
Ejemplo n.º 4
0
        public static void ExecuteSingle(BootCommand command, ref int position, ref int accumulatorValue, int argument)
        {
            switch (command)
            {
            case BootCommand.NoOperation:
                position++;
                break;

            case BootCommand.Jump:
                position += argument;
                break;

            case BootCommand.Accumulate:
                position++;
                accumulatorValue += argument;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(command), command, null);
            }
        }