Example #1
0
        public void TestValidToyMove()
        {
            // arrange
            var robot = new ToyRobot {
                Direction = Direction.East, Position = new Position(2, 2)
            };

            // act
            var nextPosition = robot.GetNextPosition();

            // assert
            Assert.AreEqual(3, nextPosition.X);
            Assert.AreEqual(2, nextPosition.Y);
        }
        public string ProcessCommand(string[] input)
        {
            var command = InputParser.ParseCommand(input);

            if (command != Command.Place && ToyRobot.Position == null)
            {
                return(string.Empty);
            }

            switch (command)
            {
            case Command.Place:
                var placeCommandParameter = InputParser.ParseCommandParameter(input);
                if (SquareBoard.IsValidPosition(placeCommandParameter.Position))
                {
                    ToyRobot.Place(placeCommandParameter.Position, placeCommandParameter.Direction);
                }
                break;

            case Command.Move:
                var newPosition = ToyRobot.GetNextPosition();
                if (SquareBoard.IsValidPosition(newPosition))
                {
                    ToyRobot.Position = newPosition;
                }
                break;

            case Command.Left:
                ToyRobot.RotateLeft();
                break;

            case Command.Right:
                ToyRobot.RotateRight();
                break;

            case Command.Report:
                return(GetReport());
            }
            return(string.Empty);
        }
Example #3
0
        public string ProcessInput(string[] input)
        {
            var command = CommandParser.ParseCommand(input);

            if (command != Command.Place && ToyRobot.Coordinates == null)
            {
                return(string.Empty);
            }

            switch (command)
            {
            case Command.Place:
                var placeCommandParameter = CommandParser.ParseCommandParameter(input);
                if (Grid.IsPositionValid(placeCommandParameter.Coordinates))
                {
                    ToyRobot.Place(placeCommandParameter.Coordinates, placeCommandParameter.Direction);
                }
                break;

            case Command.Move:
                var newPosition = ToyRobot.GetNextPosition();
                if (Grid.IsPositionValid(newPosition))
                {
                    ToyRobot.Coordinates = newPosition;
                }
                break;

            case Command.Left:
                ToyRobot.RotateLeft();
                break;

            case Command.Right:
                ToyRobot.RotateRight();
                break;

            case Command.Report:
                return(GetReport());
            }
            return(string.Empty);
        }