コード例 #1
0
        public void TestIsValidPosition_StartingPosition()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(0, 0);

            var result = squareBoard.IsValidPosition(position);
            Assert.IsTrue(result);
        }      
コード例 #2
0
        public void TestIsValidPosition_PositionInBound()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(1, 4);

            var result = squareBoard.IsValidPosition(position);
            Assert.IsTrue(result);            
        }
コード例 #3
0
 public void TestIsValidPosition_PositionOutOfBound()
 {
     SquareBoard squareBoard = new SquareBoard(5, 5);            
     Position position = new Position(6, 6);
   
     var result = squareBoard.IsValidPosition(position);
     Assert.IsFalse(result);
 }
コード例 #4
0
        public void TestIsValidPosition_NegativePosition()
        {
            SquareBoard squareBoard = new SquareBoard(5, 5);
            Position position = new Position(-1, -1);

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

        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);

        }
コード例 #9
0
        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());

        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }