Exemplo n.º 1
0
 public BaseRover(IRoverCommand init, bool debug = false)
 {
     Heading  = init.Heading;
     Position = init.Start;
     Mission  = init.Mission;
     _debug   = debug;
 }
Exemplo n.º 2
0
        public static void ExecuteRoverCommands(string roverCommands, IRover rover)
        {
            foreach (char roverCommand in TrimCommand(roverCommands))
            {
                IRoverCommand command = RoverCommandFactory(roverCommand.ToString());

                command?.Execute(rover);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public RoverInvoker(IRover rover)
        {
            _rover = rover;

            foreach (var ch in rover.CommandParams)
            {
                IRoverCommand command = GetCommand(ch);
                if (command != null)
                {
                    AddCommand(command);
                }
                else
                {
                    throw new NullReferenceException("Girilen karakter için command tanımlı değil.");
                }
            }
        }
Exemplo n.º 5
0
        /**
         * This method is used to fetch respective factory methods.
         * @param factoryType - factoryType input string
         * @return IRoverCommand - respective IRoverCommand Object
         */
        public IRoverCommand getFactory(String factoryType)
        {
            IRoverCommand command = null;

            if (factoryType.Equals(RoverConstants.MOVE_AHEAD))
            {
                command = getMoveCommand();
            }
            else if (factoryType.Equals(RoverConstants.ROTATE_LEFT))
            {
                command = getRotateLeftCommand();
            }
            else if (factoryType.Equals(RoverConstants.ROTATE_RIGHT))
            {
                command = getRotateRightCommand();
            }

            return(command);
        }
Exemplo n.º 6
0
        internal void Move(char[] moves)
        {
            this.Status.StatusCode = RoverStatus.RoverStatusCode.Ok;
            try
            {
                foreach (char commandChar in moves)
                {
                    IRoverCommand command = CommandFactory(commandChar);
                    if (command == null)
                    {
                        throw new RoverException($"invalid command character: {command}!");
                    }

                    RoverPosition newPosition = command.CalcNewPosition(this.Coordinates, this.Direction);

                    var           normalizeCoords   = _map.NormalizeCoordinates(newPosition.Coordinates);
                    RoverPosition normalizePosition = new RoverPosition(normalizeCoords, newPosition.Direction);

                    if (ObstacleDetector != null && ObstacleDetector.IsObstacleDetected(normalizePosition.Coordinates))
                    {
                        RoverStatus status = new RoverStatus(RoverStatus.RoverStatusCode.Fail)
                        {
                            StatusMessage = $"obstacle detected at: ({normalizeCoords})",
                        };

                        this.Status = status;
                        return; //don't move and report error by changing own status
                    }

                    this.Position = normalizePosition;
                }
            }
            catch (RoverException e)
            {
                this.Status = new RoverStatus(RoverStatus.RoverStatusCode.Error)
                {
                    StatusMessage = e.Message
                };
            }
        }
Exemplo n.º 7
0
 private void AddCommand(IRoverCommand c)
 {
     _commandList.Enqueue(c);
 }
Exemplo n.º 8
0
        public void Get_Null_For_InvalidCommand()
        {
            IRoverCommand command = CommandHelper.RoverCommandFactory("X");

            Assert.AreSame(null, command);
        }
Exemplo n.º 9
0
        public void Get_Turn_Right_For_R()
        {
            IRoverCommand command = CommandHelper.RoverCommandFactory("R");

            Assert.AreSame(typeof(TurnRight), command.GetType());
        }
Exemplo n.º 10
0
        public void Get_Turn_Left_For_L()
        {
            IRoverCommand command = CommandHelper.RoverCommandFactory("L");

            Assert.AreSame(typeof(TurnLeft), command.GetType());
        }
Exemplo n.º 11
0
        public void Get_Move_Forward_For_M()
        {
            IRoverCommand command = CommandHelper.RoverCommandFactory("M");

            Assert.AreSame(typeof(MoveForward), command.GetType());
        }
Exemplo n.º 12
0
 public Worker(IRoverCommand roverCommand)
 {
     _roverCommand = roverCommand;
 }
Exemplo n.º 13
0
 public static void CreateRoverCommandFrom(string[] input, IRoverFactory roverFactory)
 {
     roverCommand = new RoverCommand(input, roverFactory);
 }
Exemplo n.º 14
0
 public OptimisticRover(IRoverCommand init, bool debug = false) : base(init, debug)
 {
 }