public RoverSpaceVehicle( ITurnLeft turnLeftAlgorithm , ITurnRight turnRightAlgorithm , IAdvance advanceAlgorithm , MarsOrientations roverOrientation) { _turnLeftBehavior = turnLeftAlgorithm; _turnRightBehavior = turnRightAlgorithm; _advanceBehavior = advanceAlgorithm; _roverPositionInMars = new Position(); //Default 0 , 0 Coordination; _roverOrientationsInMars = roverOrientation; }
//private Position _roverPosition; //private MarsOrientations _roverOrientation; //public AdvanceInMars(Position roverPosition, MarsOrientations roverOrientation) //{ // _roverPosition = roverPosition; // _roverOrientation = roverOrientation; //} public Position TurnAdvance(Position roverPosition, MarsOrientations roverOrientation) { if (roverOrientation == MarsOrientations.N) { return(new Position(roverPosition.X, roverPosition.Y + 1)); } else if (roverOrientation == MarsOrientations.E) { return(new Position(roverPosition.X + 1, roverPosition.Y)); } else if (roverOrientation == MarsOrientations.S) { return(new Position(roverPosition.X, roverPosition.Y - 1)); } else if (roverOrientation == MarsOrientations.W) { return(new Position(roverPosition.X - 1, roverPosition.Y)); } else { return(roverPosition); } }
public void PerfomTurnRight() { _roverOrientationsInMars = _turnRightBehavior.TurnRight(_roverOrientationsInMars); }
public void PerformTurnLeft() { _roverOrientationsInMars = _turnLeftBehavior.TurnLeft(_roverOrientationsInMars); }
public MarsOrientations TurnRight(MarsOrientations roverOrientation) { return((roverOrientation + 1) > MarsOrientations.W ? MarsOrientations.N : roverOrientation + 1); }
public MarsOrientations TurnLeft(MarsOrientations roverOrientation) { return((roverOrientation - 1) < MarsOrientations.N ? MarsOrientations.W : roverOrientation - 1); }
public void RoverTurnRight_ShouldReturnTheCorrespondentOrientationDependingHisActualOrientation(MarsOrientations roverActualOrientation, MarsOrientations roverFinalOrientation) { var stub = new RoverSpaceVehicle( _turnLeftAlgorithm , _turnRightAlgorithm , _advanceAlgorithm , roverActualOrientation); stub.PerfomTurnRight(); Assert.Equal(roverFinalOrientation, stub._roverOrientationsInMars); }