Example #1
0
        public void Move_InvalidCommand_Error()
        {
            //Arrange
            Point startingPoint = new Point(0, 0);

            MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North;
            MarsRover rover = new MarsRover(startingPoint, startingDirection, null, null);

            //Act
            rover.Move(new[] { '?' });

            //Assert
            Assert.AreEqual(RoverStatus.RoverStatusCode.Error, rover.Status.StatusCode);
        }
Example #2
0
        public void CommandFactory_InvalidCommand_Null()
        {
            //Arrange
            Point startingPoint = new Point(0, 0);

            MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North;
            MarsRover rover = new MarsRover(startingPoint, startingDirection, null, null);

            //Act
            IRoverCommand cmd = rover.CommandFactory('?');

            //Assert
            Assert.IsNull(cmd);
        }
Example #3
0
        protected Vector CalcNextMove(MarsRover.CardinalDirection direction)
        {
            switch (direction)
            {
            case MarsRover.CardinalDirection.North:
                return(new Vector(0, 1));

            case MarsRover.CardinalDirection.East:
                return(new Vector(1, 0));

            case MarsRover.CardinalDirection.South:
                return(new Vector(0, -1));

            case MarsRover.CardinalDirection.West:
                return(new Vector(-1, 0));

            default:
                throw new RoverException($"enum member '{direction}' does not have a corresponding switch case");
            }
        }
Example #4
0
        protected override MarsRover.CardinalDirection CalcNewDirection(MarsRover.CardinalDirection direction)
        {
            switch (direction)
            {
            case MarsRover.CardinalDirection.East:
                return(MarsRover.CardinalDirection.North);

            case MarsRover.CardinalDirection.South:
                return(MarsRover.CardinalDirection.East);

            case MarsRover.CardinalDirection.West:
                return(MarsRover.CardinalDirection.South);

            case MarsRover.CardinalDirection.North:
                return(MarsRover.CardinalDirection.West);

            default:
                throw new RoverException($"enum member '{direction}' does not have a corresponding switch case");
            }
        }
Example #5
0
        public void TurnRight_00N_00E()
        {
            //Arrange
            Point startingPoint = new Point(0, 0);

            MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North;
            MarsRover rover = new MarsRover(startingPoint, startingDirection);
            var       moves = new[] { 'r' };

            Point expectedCoordinates = new Point(0, 0);

            MarsRover.CardinalDirection expectedStartingDirection = MarsRover.CardinalDirection.East;

            //Act
            rover.Move(moves);

            //Assert
            Assert.AreEqual(expectedCoordinates, rover.Coordinates);
            Assert.AreEqual(expectedStartingDirection, rover.Direction);
            Assert.AreEqual(RoverStatus.RoverStatusCode.Ok, rover.Status.StatusCode);
        }
Example #6
0
        public void MoveOneStepBacward_b_00()
        {
            //Arrange
            Point startingPoint = new Point(0, 1);

            MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North;
            MarsRover rover = new MarsRover(startingPoint, startingDirection);
            var       moves = new[] { 'b' };

            Point expectedCoordinates = new Point(0, 0);

            MarsRover.CardinalDirection expectedStartingDirection = MarsRover.CardinalDirection.North;

            //Act
            rover.Move(moves);

            //Assert
            Assert.AreEqual(expectedCoordinates, rover.Coordinates);
            Assert.AreEqual(expectedStartingDirection, rover.Direction);
            Assert.AreEqual(RoverStatus.RoverStatusCode.Ok, rover.Status.StatusCode);
        }
Example #7
0
        public void CrossingOverEdgeOfGrid_00Nb_0MaxY()
        {
            //Arrange
            const int width  = 10;
            const int height = 10;

            Point startingPoint = new Point(0, 0); //(0,9)

            MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North;

            Grid      map   = new Grid(width, height);
            MarsRover rover = new MarsRover(startingPoint, startingDirection, map, null);
            var       moves = new[] { 'b' };

            Point expectedCoordinates = new Point(0, width - 1); //crossing the grid leads to Y coordinate 0

            //Act
            rover.Move(moves);

            //Assert
            Assert.AreEqual(expectedCoordinates, rover.Coordinates);
            Assert.AreEqual(RoverStatus.RoverStatusCode.Ok, rover.Status.StatusCode);
        }
Example #8
0
 public abstract RoverPosition CalcNewPosition(Point coordinates, MarsRover.CardinalDirection direction);
Example #9
0
 public RoverPosition(Point coordinates, MarsRover.CardinalDirection direction)
 {
     this.Coordinates = coordinates;
     this.Direction   = direction;
 }
Example #10
0
        public RoverPosition CalcNewPosition(Point coordinates, MarsRover.CardinalDirection direction)
        {
            var newDirectaion = CalcNewDirection(direction);

            return(new RoverPosition(coordinates, newDirectaion)); //rover only turns
        }
Example #11
0
 protected abstract MarsRover.CardinalDirection CalcNewDirection(MarsRover.CardinalDirection direction);