Example #1
0
 public MarsRover(MarsRoverGrid grid)
 {
     _grid             = grid;
     _currentDirection = "N";
     _currentPosition  = new Coordinate(0, 0);
     _rotator          = new MarsRoverRotator();
 }
Example #2
0
 public void ShouldThrowExceptionSetPositionIsCalledAndGridIsAlreadyOccupied()
 {
     _marsRoverGrid = new MarsRoverGrid();
     _marsRoverGrid.SetMarsRoverGridBoundary(5, 5);
     _marsRoverGrid.SetRoverStartPosition(3, 3);
     Assert.Throws <GridSpaceOccupiedException>(() => _marsRoverGrid.SetRoverStartPosition(3, 3));
 }
Example #3
0
 public void ShouldCreateGridOfSpecifiedSize()
 {
     _marsRoverGrid = new MarsRoverGrid();
     _marsRoverGrid.SetMarsRoverGridBoundary(5, 6);
     Assert.AreEqual(5, _marsRoverGrid.GetFloorSpaceLength());
     Assert.AreEqual(6, _marsRoverGrid.GetGridWidth());
 }
Example #4
0
        public void StopBeforeAnObstacle(string command, string expectedOutput)
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(0, 3)
            };
            var gridWithObstacles = new MarsRoverGrid(10, 10, obstacles);
            var rover             = new MarsRover(gridWithObstacles);

            rover.Execute(command).ShouldBe(expectedOutput);
        }
Example #5
0
        public void DodgeMultipleObstacles(string command, string expectedOutput)
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(0, 3),
                new Coordinate(3, 0),
                new Coordinate(0, 7),
                new Coordinate(7, 0)
            };
            var gridWithObstacles = new MarsRoverGrid(10, 10, obstacles);
            var rover             = new MarsRover(gridWithObstacles);

            rover.Execute(command).ShouldBe(expectedOutput);
        }
Example #6
0
        public void ShouldThrowExceptionWhenYouMoveRoverOffEdge()
        {
            _marsRoverGrid = new MarsRoverGrid();
            _marsRoverGrid.SetMarsRoverGridBoundary(5, 5);
            var rover = new Rover.Core.Entities.Rover()
            {
                GridPosition = new YAndXCoordinate {
                    X = 2, Y = 2
                }
            };

            Assert.Throws <RoverWillDriveOffGridException>(() => _marsRoverGrid.MoveRoverTo(rover, 6, 5));
        }
Example #7
0
        public void ShouldThrowExceptionWhenYouMoveRoverToACellThatIsOccupied()
        {
            _marsRoverGrid = new MarsRoverGrid();
            _marsRoverGrid.SetMarsRoverGridBoundary(5, 5);
            _marsRoverGrid.SetRoverStartPosition(3, 3);
            var rover = new Rover.Core.Entities.Rover()
            {
                GridPosition = new YAndXCoordinate {
                    X = 2, Y = 2
                }
            };

            Assert.Throws <GridSpaceOccupiedException>(() => _marsRoverGrid.MoveRoverTo(rover, 3, 3));
        }
Example #8
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());
        }