public void TestIsValidPosition_StartingPosition()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(0, 0);

            var result = squareBoard.IsValidPosition(position);
            Assert.IsTrue(result);
        }      
        public void TestIsValidPosition_PositionInBound()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(1, 4);

            var result = squareBoard.IsValidPosition(position);
            Assert.IsTrue(result);            
        }
 public void TestIsValidPosition_PositionOutOfBound()
 {
     SquareBoard squareBoard = new SquareBoard(5, 5);            
     Position position = new Position(6, 6);
   
     var result = squareBoard.IsValidPosition(position);
     Assert.IsFalse(result);
 }
        public void TestIsValidPosition_NegativePosition()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(-1, -1);

            var result = squareBoard.IsValidPosition(position);
            Assert.IsFalse(result);

        }
 /// <summary>
 /// Determines the next position of the robot based on the direction it's currently facing.
 /// </summary>
 /// <returns>Next position</returns>
 public Position GetNextPosition()
 {
     var newPosition = new Position(Position.X, Position.Y);
     switch (Direction)
     {
         case Direction.North:
             newPosition.Y = newPosition.Y + 1;
             break;
         case Direction.East:
             newPosition.X = newPosition.X + 1;
             break;
         case Direction.South:
             newPosition.Y = newPosition.Y - 1;
             break;
         case Direction.West:
             newPosition.X = newPosition.X - 1;
             break;
     }
     return newPosition;
 }
        /// <summary>        
        /// Parsers the robot's initial position and the direction it is going to be facing.        
        /// </summary>
        /// <exception cref="ArgumentException">Throws when raw input does not match the "PLACE" command parameter pattern.</exception>
        /// <param name="input">Input provided (input is split by blank space)</param>
        /// <returns>Place command parameter</returns>
        public ICommandParameter ParseParameters(string[] input)
        {
            Direction direction;
            Position position = null;

            //Ensure that Place command is followed by valid command parameters (X,Y and F robot's face direction).
            if (input.Length < CommandInputCount || input.Length > CommandInputCount)
                throw new ArgumentException("Incomplete command. Please ensure that the PLACE command is using format: PLACE X,Y,F");

            //Ensure that three command parameters are provided for the PLACE command.   
            var commandParams = input[1].Split(',');
            if (commandParams.Length < ParameterCount || commandParams.Length > ParameterCount)
                throw new ArgumentException("Incomplete command. Please ensure that the PLACE command is using format: PLACE X,Y,F");

            //Parse the direction which the robot is going to be facing.
            if (!Enum.TryParse(commandParams[commandParams.Length - 1], true, out direction))
                throw new ArgumentException("Invalid direction. Please select from one of the following directions: NORTH|EAST|SOUTH|WEST");
            
            var x = Convert.ToInt32(commandParams[0]);
            var y = Convert.ToInt32(commandParams[1]);
            position = new Position(x, y);

            return new PlaceCommandParameter(position, direction);
        }
        public void TestPlaceRobot_ValidPositonAndDirection()
        {
            var position = new Position(1, 1);
            var robot = new ToyRobot();

            robot.Place(position, Direction.East);

            Assert.AreEqual(1, robot.Position.X);
            Assert.AreEqual(1, robot.Position.Y);
        }
 /// <summary>
 /// Sets the robot's position and direction.
 /// </summary>
 /// <param name="position">Position of a robot on a square board.</param>
 /// <param name="direction">direction which the robot will be facing.</param>
 public void Place(Position position, Direction direction)
 {
     this.Position = position;
     this.Direction = direction;
 }
 public PlaceCommandParameter(Position position,Direction direction)
 {
     Position = position;
     Direction = direction;
 }
 /// <summary>
 /// Check whether the position specified is inside the boundaries of the square board.
 /// </summary>
 /// <param name="position"></param>
 /// <returns>true if positions are within the boundaries of the square board</returns>
 public bool IsValidPosition(Position position)
 {
     return position.X < Columns && position.X >= 0 && 
            position.Y < Rows && position.Y >= 0;
 }