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); }
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); }
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"); } }
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"); } }
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); }
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); }
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); }
public abstract RoverPosition CalcNewPosition(Point coordinates, MarsRover.CardinalDirection direction);
public RoverPosition(Point coordinates, MarsRover.CardinalDirection direction) { this.Coordinates = coordinates; this.Direction = direction; }
public RoverPosition CalcNewPosition(Point coordinates, MarsRover.CardinalDirection direction) { var newDirectaion = CalcNewDirection(direction); return(new RoverPosition(coordinates, newDirectaion)); //rover only turns }
protected abstract MarsRover.CardinalDirection CalcNewDirection(MarsRover.CardinalDirection direction);