public void TestInvalidBehaviourPlace()
        {
            // arrange
            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

            // act
            simulator.ProcessCommand("PLACE 9,7,EAST".Split(' '));

            // assert
            Assert.IsNull(robot.Position);
        }
        public void TestValidBehaviourMove()
        {
            // arrange
            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

            // act
            simulator.ProcessCommand("PLACE 0,0,NORTH".Split(' '));
            simulator.ProcessCommand("MOVE".Split(' '));

            // assert
            Assert.AreEqual("Output: 0,1,NORTH", simulator.GetReport());
        }
        public void TestValidBehaviourPlace()
        {
            // arrange
            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

            // act
            simulator.ProcessCommand("PLACE 1,4,EAST".Split(' '));

            // assert
            Assert.AreEqual(1, robot.Position.X);
            Assert.AreEqual(4, robot.Position.Y);
            Assert.AreEqual(Direction.East, robot.Direction);
        }
        public void TestValidBehaviourReport3()
        {
            // arrange
            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

            // act
            simulator.ProcessCommand("PLACE 0,0,NORTH".Split(' '));
            simulator.ProcessCommand("LEFT".Split(' '));

            var output = simulator.ProcessCommand("REPORT".Split(' '));

            // assert
            Assert.AreEqual("Output: 0,0,WEST", output);
        }
        public void TestInvalidBehaviourMove()
        {
            // arrange
            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

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

            // assert
            Assert.AreEqual("Output: 2,4,NORTH", simulator.GetReport());
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            string description = ToyRobotApp.Constants.Messages.MENU;

            IToyBoard    toyBoard    = new ToyBoard(5, 5);
            IInputParser inputParser = new InputParser();
            IToyRobot    robot       = new ToyRobot();
            var          simulator   = new ToyAction(robot, toyBoard, inputParser);

            var stopApplication = false;

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

                if (command.ToUpper().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);
        }