Пример #1
0
        static void Main(string[] args)
        {
            //"5 5\r\n1 2 N\r\nLML\r\n3 4 E\r\nMM$"
            var stringCommand                       = "10 10\r\n1 2 N\r\nLML\r\n3 4 E\r\nMMR\r\n6 6 N\r\nMMMLMM";
            var commandParser                       = new CommandParser();
            var roverProvider                       = new RoverProvider();
            var roverDisplay                        = new DisplayRoverInformation(roverProvider);
            var roverGrid                           = new MarsRoverGrid();
            var commands                            = commandParser.CreateCommandsFrom(stringCommand);
            var createGridCommandHandler            = new CreateGridCommandHandler(roverGrid);
            var createRoverCommandHandler           = new CreateRoverCommandHandler(roverProvider);
            var roverActionCommandHandler           = new RoverActionCommandHandler(roverGrid, new RoverActonToCoordinateTranslationService(new RoverActionToDirection()), roverProvider);
            var setRoverStartPositionCommandHandler = new SetRoverStartPositionCommandHandler(roverGrid);

            createGridCommandHandler.Handle(commands);
            createRoverCommandHandler.Handle(commands.RoverMovementCommands);
            setRoverStartPositionCommandHandler.Handle(commands.RoverMovementCommands);
            roverActionCommandHandler.Handle(commands);
            Console.WriteLine(roverDisplay.GetRoverInformation());
        }
Пример #2
0
        public void ShouldParseCommandStringIntoCommandStructure()
        {
            _commandParser = new CommandParser();
            var result = _commandParser.CreateCommandsFrom($"5 6\r\n1 2 N\r\nLML\r\n3 4 E\r\nMM$");

            var firstRoverCommand  = result.RoverMovementCommands.OrderBy(rover => rover.RoverCreationOrder).First();
            var secondRoverCommand =
                result.RoverMovementCommands.OrderBy(rover => rover.RoverCreationOrder).Skip(1).First();

            Assert.AreEqual(5, result.GridSize.Y);;
            Assert.AreEqual(6, result.GridSize.X);
            Assert.AreEqual(1, firstRoverCommand.RoverStartPositionCommand.GridPosition.Y);
            Assert.AreEqual(2, firstRoverCommand.RoverStartPositionCommand.GridPosition.X);
            Assert.AreEqual(Direction.North, firstRoverCommand.RoverStartPositionCommand.RoverFacingDirection);
            Assert.AreEqual(3, firstRoverCommand.RoverMovementCommands.Count());
            Assert.AreEqual(3, secondRoverCommand.RoverStartPositionCommand.GridPosition.Y);
            Assert.AreEqual(4, secondRoverCommand.RoverStartPositionCommand.GridPosition.X);
            Assert.AreEqual(Direction.East, secondRoverCommand.RoverStartPositionCommand.RoverFacingDirection);
            Assert.AreEqual(2, secondRoverCommand.RoverMovementCommands.Count());
        }