Beispiel #1
0
        public string Command(string command)
        {
            var             response    = "";
            InstructionArgs args        = null;
            var             instruction = GetInstruction(command, ref args);

            switch (instruction)
            {
            case Instruction.Place:
                var placeArgs = (PlaceArgs)args;
                response = _robotAction.Place(placeArgs.X, placeArgs.Y, placeArgs.Facing) ? "Command Success" : _robotAction.Error;
                break;

            case Instruction.Move:
                response = _robotAction.Move() ? "Command Success" : _robotAction.Error;
                break;

            case Instruction.Left:
                response = _robotAction.Left() ? "Command Success" : _robotAction.Error;
                break;

            case Instruction.Right:
                response = _robotAction.Right() ? "Command Success" : _robotAction.Error;
                break;

            case Instruction.Report:
                response = _robotAction.Report();
                break;

            case Instruction.Invalid:
                response = @"Invalid command. The correct command formats are as follows:
                    PLACE X, Y, DIRECTION
                    MOVE
                    RIGHT
                    LEFT
                    REPORT
                    -------------
                    Please review your input and try again.";
                break;

            default:
                response = @"Invalid command. The correct command formats are as follows:
                    PLACE X, Y, DIRECTION
                    MOVE
                    RIGHT
                    LEFT
                    REPORT
                    -------------
                    Please review your input and try again.";
                break;
            }
            return(response);
        }
        public void Robot_NotPlaced_AndTryToMove()
        {
            var result = robotAction.Move();

            Assert.IsFalse(result);
            Assert.AreEqual("Robot cannot move until it has been placed on the table.", robotAction.Error);
        }