Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        //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);
            }
        }
Esempio n. 3
0
 public void PerfomTurnRight()
 {
     _roverOrientationsInMars = _turnRightBehavior.TurnRight(_roverOrientationsInMars);
 }
Esempio n. 4
0
 public void PerformTurnLeft()
 {
     _roverOrientationsInMars = _turnLeftBehavior.TurnLeft(_roverOrientationsInMars);
 }
Esempio n. 5
0
 public MarsOrientations TurnRight(MarsOrientations roverOrientation)
 {
     return((roverOrientation + 1) > MarsOrientations.W ? MarsOrientations.N : roverOrientation + 1);
 }
Esempio n. 6
0
 public MarsOrientations TurnLeft(MarsOrientations roverOrientation)
 {
     return((roverOrientation - 1) < MarsOrientations.N ? MarsOrientations.W : roverOrientation - 1);
 }
Esempio n. 7
0
        public void RoverTurnRight_ShouldReturnTheCorrespondentOrientationDependingHisActualOrientation(MarsOrientations roverActualOrientation, MarsOrientations roverFinalOrientation)
        {
            var stub = new RoverSpaceVehicle(
                _turnLeftAlgorithm
                , _turnRightAlgorithm
                , _advanceAlgorithm
                , roverActualOrientation);

            stub.PerfomTurnRight();

            Assert.Equal(roverFinalOrientation, stub._roverOrientationsInMars);
        }