Ejemplo n.º 1
0
        public void It_starts_at_the_point_given()
        {
            var startingPosition = new Position(5, 5);

            var rover = new MarsRover(startingPosition);
            Assert.That(rover.Position, Is.EqualTo(startingPosition));
        }
Ejemplo n.º 2
0
 public void ProcessCommands(String commands, MarsRover rover)
 {
     foreach (var command in commands)
     {
         rover = ConsumeCommand(command, rover);
     }
 }
Ejemplo n.º 3
0
 public void ProcessCommands(Char[] commands, MarsRover rover)
 {
     foreach (var command in commands)
     {
         ConsumeCommand(command, rover);
     }
 }
Ejemplo n.º 4
0
        public MarsRover MoveRoverTo(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate)
        {
            if (!MoveIsValid(rover, xCoordinate, yCoordinate))
            {
                return(rover);
            }

            var noObstacleFound = NoObstacleAt(xCoordinate, yCoordinate);

            if (RoverCanBeMoved(xCoordinate, yCoordinate, noObstacleFound))
            {
                if (active)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    gridMap[xCoordinate, yCoordinate]             = RoverSymbol;
                }
                rover.XCoordinate = xCoordinate;
                rover.YCoordinate = yCoordinate;
            }
            else if (XCoordinateOnOuterEdge(xCoordinate))
            {
                if (xCoordinate == -1)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.XCoordinate = gridWidth - 1;
                    gridMap[rover.XCoordinate, yCoordinate] = RoverSymbol;
                }
                else
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.XCoordinate = 0;
                    gridMap[rover.XCoordinate, yCoordinate] = RoverSymbol;
                }
            }
            else if (YCoordinateOnOuterEdge(yCoordinate))
            {
                if (yCoordinate == -1)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.YCoordinate = gridHeight - 1;
                    gridMap[xCoordinate, rover.YCoordinate] = RoverSymbol;
                }
                else
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.YCoordinate = 0;
                    gridMap[xCoordinate, rover.YCoordinate] = RoverSymbol;
                }
            }

            if (!noObstacleFound)
            {
                rover.AtObstacle          = true;
                rover.ObstableXCoordinate = xCoordinate;
                rover.ObstableYCoordinate = yCoordinate;
            }

            return(rover);
        }
Ejemplo n.º 5
0
        public MarsRover MoveRoverTo(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate)
        {
            if (!MoveIsValid(rover, xCoordinate, yCoordinate))
                return rover;

            var noObstacleFound = NoObstacleAt(xCoordinate, yCoordinate);

            if (RoverCanBeMoved(xCoordinate, yCoordinate, noObstacleFound))
            {
                if (active)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    gridMap[xCoordinate, yCoordinate] = RoverSymbol;
                }
                rover.XCoordinate = xCoordinate;
                rover.YCoordinate = yCoordinate;
            }
            else if (XCoordinateOnOuterEdge(xCoordinate))
            {
                if (xCoordinate == -1)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.XCoordinate = gridWidth - 1;
                    gridMap[rover.XCoordinate, yCoordinate] = RoverSymbol;
                }
                else
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.XCoordinate = 0;
                    gridMap[rover.XCoordinate, yCoordinate] = RoverSymbol;
                }
            }
            else if (YCoordinateOnOuterEdge(yCoordinate))
            {
                if (yCoordinate == -1)
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.YCoordinate = gridHeight - 1;
                    gridMap[xCoordinate, rover.YCoordinate] = RoverSymbol;
                }
                else
                {
                    gridMap[rover.XCoordinate, rover.YCoordinate] = VisitedSymbol;
                    rover.YCoordinate = 0;
                    gridMap[xCoordinate, rover.YCoordinate] = RoverSymbol;
                }
            }

            if (!noObstacleFound)
            {
                rover.AtObstacle = true;
                rover.ObstableXCoordinate = xCoordinate;
                rover.ObstableYCoordinate = yCoordinate;
            }

            return rover;
        }
Ejemplo n.º 6
0
 public void GridToStringWorks()
 {
     grid.PlaceObstacleAt(4, 4);
     grid.PlaceObstacleAt(0, 0);
     marsRover = new MarsRover(grid, 0, 4, DirectionConstants.East);
     marsRover.RunRoverWithCommands("f");
     var stringGrid = marsRover.PrintMap();
     System.Diagnostics.Debug.WriteLine(stringGrid);
     Assert.AreEqual(".R__X\n_____\n_____\n_____\nX____\n", stringGrid);
 }
Ejemplo n.º 7
0
        public void RoverStopsAtObstacleInMultiStepPath()
        {
            grid.PlaceObstacleAt(4, 4);
            marsRover = new MarsRover(grid, 0, 0, DirectionConstants.East);
            marsRover.RunRoverWithCommands("fflffrflffrf");
            Assert.IsTrue(marsRover.AtObstacle);

            var stringGrid = marsRover.PrintMap();
            System.Diagnostics.Debug.WriteLine(stringGrid);
        }
Ejemplo n.º 8
0
        public void RoverStopsAtObstacleInPath(Char initialDirection)
        {
            grid.PlaceObstacleAt(1, 0);
            grid.PlaceObstacleAt(2, 1);
            grid.PlaceObstacleAt(0, 1);
            grid.PlaceObstacleAt(1, 2);
            marsRover = new MarsRover(grid, 1, 1, initialDirection);
            marsRover.RunRoverWithCommands("f");
            Assert.IsTrue(marsRover.AtObstacle);

            var stringGrid = marsRover.PrintMap();
            System.Diagnostics.Debug.WriteLine(stringGrid);
        }
Ejemplo n.º 9
0
        private Boolean MoveIsValid(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate)
        {
            var xDiff     = rover.XCoordinate - xCoordinate;
            var yDiff     = rover.YCoordinate - yCoordinate;
            var yAxisMove = xDiff == 0 && Math.Abs(yDiff) == 1;
            var xAxisMove = Math.Abs(xDiff) == 1 && yDiff == 0;

            if (xAxisMove ^ yAxisMove)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        public MarsRover PlaceRover(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate, Char direction)
        {
            if (RoverCanBePlaced(xCoordinate, yCoordinate))
            {
                rover.XCoordinate = xCoordinate;
                rover.YCoordinate = yCoordinate;
                if (active)
                {
                    gridMap[xCoordinate, yCoordinate] = RoverSymbol;
                }
            }

            return(rover);
        }
Ejemplo n.º 11
0
        private MarsRover ConsumeCommand(Char command, MarsRover rover)
        {
            var lowercaseCommand = Char.ToLower(command);

            if (lowercaseCommand == CommandConstants.Forward)
                return roverModel.MoveForward(rover);
            else if (lowercaseCommand == CommandConstants.Backwards)
                return roverModel.MoveBackwards(rover);
            else if (lowercaseCommand == CommandConstants.Right)
                return roverModel.TurnRight(rover);
            else if (lowercaseCommand == CommandConstants.Left)
                return roverModel.TurnLeft(rover);

            return rover;
        }
Ejemplo n.º 12
0
        private MarsRover ConsumeCommand(Char command, MarsRover rover)
        {
            var lowercaseCommand = Char.ToLower(command);

            if (lowercaseCommand == CommandConstants.Forward)
            {
                return(roverModel.MoveForward(rover));
            }
            else if (lowercaseCommand == CommandConstants.Backwards)
            {
                return(roverModel.MoveBackwards(rover));
            }
            else if (lowercaseCommand == CommandConstants.Right)
            {
                return(roverModel.TurnRight(rover));
            }
            else if (lowercaseCommand == CommandConstants.Left)
            {
                return(roverModel.TurnLeft(rover));
            }

            return(rover);
        }
Ejemplo n.º 13
0
 public void Initialize()
 {
     marsRover = new MarsRover(new Grid(10000, 10000), InitialXCoordinate, InitialYCoordinate, InitialRoverDirection);
 }
Ejemplo n.º 14
0
        public void RoverFullMovement(Char initialDirection, Int32 initialXCoordinate, Int32 initialYCoordinate, String commands, Char endingDireciton, Int32 endingXCoordinate, Int32 endingYCoordinate)
        {
            var rover = new MarsRover(initialXCoordinate, initialYCoordinate, initialDirection);

            rover.RunRoverWithCommands(commands);
            Assert.That(rover.roverState.Direction, Is.EqualTo(endingDireciton));
            Assert.That(rover.XCoordinate, Is.EqualTo(endingXCoordinate));
            Assert.That(rover.YCoordinate, Is.EqualTo(endingYCoordinate));
        }
Ejemplo n.º 15
0
        public void VerifyRoverWrapsFromRightOfGridToLeft()
        {
            marsRover = new MarsRover(grid, 4, 0, DirectionConstants.East);
            marsRover.RunRoverWithCommands("f");
            Assert.AreEqual(0, marsRover.XCoordinate);
            Assert.AreEqual(0, marsRover.YCoordinate);
            marsRover.XCoordinate = 6;

            var stringGrid = marsRover.PrintMap();
            System.Diagnostics.Debug.WriteLine(stringGrid);
        }
Ejemplo n.º 16
0
 public void ProcessCommands(String commands, MarsRover rover)
 {
     foreach (var command in commands)
         rover = ConsumeCommand(command, rover);
 }
Ejemplo n.º 17
0
 public void ProcessCommands(Char[] commands, MarsRover rover)
 {
     foreach (var command in commands)
         ConsumeCommand(command, rover);
 }
Ejemplo n.º 18
0
 public CommandForward(MarsRover marsRover)
 {
     this.marsRover = marsRover;
 }
Ejemplo n.º 19
0
        public MarsRover PlaceRover(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate, Char direction)
        {
            if (RoverCanBePlaced(xCoordinate, yCoordinate))
            {
                rover.XCoordinate = xCoordinate;
                rover.YCoordinate = yCoordinate;
                if (active)
                    gridMap[xCoordinate, yCoordinate] = RoverSymbol;
            }

            return rover;
        }
Ejemplo n.º 20
0
        public void RoverUnitVectors(Char initialDirection, String commands, Int32 endingXCoordinate, Int32 endingYCoordinate)
        {
            var rover = new MarsRover(InitialXCoordinate, InitialYCoordinate, initialDirection);

            rover.RunRoverWithCommands(commands);
            Assert.That(rover.XCoordinate, Is.EqualTo(endingXCoordinate));
            Assert.That(rover.YCoordinate, Is.EqualTo(endingYCoordinate));
        }
Ejemplo n.º 21
0
 public void SetUp()
 {
     grid = new Grid(5, 5);
     marsRover = new MarsRover(InitialXCoordinate, InitialYCoordinate, InitialRoverDirection);
 }
Ejemplo n.º 22
0
        private Boolean MoveIsValid(MarsRover rover, Int32 xCoordinate, Int32 yCoordinate)
        {
            var xDiff = rover.XCoordinate - xCoordinate;
            var yDiff = rover.YCoordinate - yCoordinate;
            var yAxisMove = xDiff == 0 && Math.Abs(yDiff) == 1;
            var xAxisMove = Math.Abs(xDiff) == 1 && yDiff == 0;

            if (xAxisMove ^ yAxisMove)
                return true;

            return false;
        }
Ejemplo n.º 23
0
 public void Initialize()
 {
     marsRover = new MarsRover(InitialXCoordinate, InitialYCoordinate, InitialRoverDirection);
 }
Ejemplo n.º 24
0
 public void RoverDirectionSetWithLowerCaseIsNorth()
 {
     var lowerCaseRover = new MarsRover(0, 0, DirectionConstants.North);
     var roverDirection = lowerCaseRover.roverState.Direction;
     Assert.That(InitialRoverDirection, Is.EqualTo(roverDirection));
 }
Ejemplo n.º 25
0
        public void VerifyRoverWrapsFromBottomOfGridToTheTop()
        {
            marsRover = new MarsRover(grid, 2, 0, DirectionConstants.South);
            marsRover.RunRoverWithCommands("f");
            Assert.AreEqual(2, marsRover.XCoordinate);
            Assert.AreEqual(4, marsRover.YCoordinate);

            var stringGrid = marsRover.PrintMap();
            System.Diagnostics.Debug.WriteLine(stringGrid);
        }
Ejemplo n.º 26
0
        public void RoverTurning(Char initialDirection, String commands, Char endingDireciton)
        {
            var rover = new MarsRover(InitialXCoordinate, InitialYCoordinate, initialDirection);

            rover.RunRoverWithCommands(commands);
            Assert.That(rover.roverState.Direction, Is.EqualTo(endingDireciton));
        }