public void TestRotate_LeftAndRight()
 {
     var robot = new ToyRobot { Direction = Direction.North, Position = new Position(0, 0) };
     robot.RotateLeft();
     robot.RotateRight();
     Assert.AreEqual(Direction.North, robot.Direction);
 }
 public void TestRotateRight_DoubleRightRotation()
 {
     var robot = new ToyRobot { Direction = Direction.East, Position = new Position(0, 0) };
     robot.RotateRight();
     robot.RotateRight();
     Assert.AreEqual(Direction.West, robot.Direction);
 }
        public void TestGetNextPosition_CurrentDirectionSouth()
        {
            var robot = new ToyRobot { Direction = Direction.South, Position = new Position(0, 1) };
            var nextPosition = robot.GetNextPosition();

            Assert.AreEqual(0, nextPosition.X);
            Assert.AreEqual(0, nextPosition.Y);
        }
        public void TestGetNextPosition_CurrentDirectionEast()
        {
            var robot = new ToyRobot { Direction = Direction.East, Position = new Position(0, 0) };
            var nextPosition = robot.GetNextPosition();

            Assert.AreEqual(1, nextPosition.X);
            Assert.AreEqual(0, nextPosition.Y);
        }
        public void TestProcessCommand_InvalidRobotPlacement()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 6,6,EAST".Split(' '));

            Assert.IsNull(robot.Position);
        }
        public void TestProcessCommand_MoveToyRobot()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 0,0,NORTH".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));

            Assert.AreEqual("Output: 0,1,NORTH", simulator.GetReport());
        }
        public void TestProcessCommand_PlaceToyRobot()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 1,2,EAST".Split(' '));

            Assert.AreEqual(1, robot.Position.X);
            Assert.AreEqual(2, robot.Position.Y);
            Assert.AreEqual(Direction.East, robot.Direction);
        }
        public static void Main(string[] args)
        {
            const string description =
@"Hello and Welcome to the Toy Robot simulator!
  1: Start of by placing the robot on a square grid with dimensions of 5 X 5.
     Use the following command to place the robot.

     PLACE X,Y, F (F = NORTH SOUTH EAST or WEST)

  2: Once the robot is placed, interact with it using the following commands.
                
     MOVE – Moves the robot 1 unit to the direction it is facing.
     LEFT – Rotates the robot to 90 degrees in the left direction.
     RIGHT – Rotates the robot 90 degrees in the right direction.
     REPORT – Queries the current stats of the robot. 
     EXIT – Close Toy Robot Simulator.
";

            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();
            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);

            var stopApplication = false;
            Console.WriteLine(description);
            do
            {
                var command = Console.ReadLine();
                if (command == null) continue;

                if (command.Equals("EXIT"))
                    stopApplication = true;
                else
                {
                    try
                    {
                        var output = simulator.ProcessCommand(command.Split(' '));
                        if (!string.IsNullOrEmpty(output))
                            Console.WriteLine(output);
                    }
                    catch (ArgumentException exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
            } while (!stopApplication);

        }
        public void TestProcessCommand_TryDestroyToyRobot()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 0,0,NORTH".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            simulator.ProcessCommand("LEFT".Split(' '));

            // if the robot goes out of the board it ignores the command
            simulator.ProcessCommand("MOVE".Split(' '));

            Assert.AreEqual("Output: 0,1,WEST", simulator.GetReport());

        }
        public void TestProcessCommand_RotateAndMove()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 0,0,NORTH".Split(' '));
            simulator.ProcessCommand("RIGHT".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            simulator.ProcessCommand("LEFT".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            var output = simulator.ProcessCommand("REPORT".Split(' '));

            Assert.AreEqual("Output: 1,1,NORTH", output);
        }
        public void TestProcessCommand_ReportCommand()
        {
            ISquareBoard squareBoard = new SquareBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot robot = new ToyRobot();

            var simulator = new Simulator.Simulator(robot, squareBoard, inputParser);
            simulator.ProcessCommand("PLACE 1,2,EAST".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            simulator.ProcessCommand("LEFT".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));
            var output = simulator.ProcessCommand("REPORT".Split(' '));

            Assert.AreEqual("Output: 3,3,NORTH", output);
        }
        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);
        }
 public void TestRotateLeft_SingleLeftRotation()
 {
     var robot = new ToyRobot { Direction = Direction.East, Position = new Position(0, 0) };            
     robot.RotateLeft();
     Assert.AreEqual(Direction.North,robot.Direction);
 }