Exemple #1
0
        public void Left_NonExistentRobot_ExceptionThrown()
        {
            _coordinator.InitializeBoard(5, 5);

            var ex = Assert.Throws <Exception>(() =>
            {
                _coordinator.Left(Guid.NewGuid());
            });

            Assert.AreEqual("Robot for specified id does not exist", ex.Message);
        }
Exemple #2
0
        public (bool isRobotPlaced, string report) ProcessCommand(string[] input)
        {
            var command = input[0].ToLower();

            switch (command)
            {
            case "place":
                if (input.Length == 1)
                {
                    throw new Exception(
                              "Please provide X, Y location and Facing direction for robot to be placed on board");
                }
                var args = CalculatePlaceArguments(input[1]);
                if (_currentRobot == Guid.Empty)
                {
                    _currentRobot = _coordinator.Place(args.x, args.y, args.direction);
                }
                else
                {
                    _coordinator.Place(_currentRobot, args.x, args.y, args.direction);
                }
                break;

            case "left":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Left(_currentRobot);
                break;

            case "right":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Right(_currentRobot);
                break;

            case "move":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Move(_currentRobot);
                break;

            case "report":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                var report       = _coordinator.Report().First();
                var reportString = $"Output: {report.x},{report.y},{report.direction}";
                return(_currentRobot != Guid.Empty, reportString);

            default:
                throw new Exception("Command not recognized please try again");
            }

            return(_currentRobot != Guid.Empty, string.Empty);
        }