public void GetOutputTest()
        {
            var roverCommand = new RoverCommand();
            var res          = roverCommand.GetOutput();

            Assert.Equal("output was written to the console", res);
        }
Beispiel #2
0
        private static void Execute(Rover rover, ModifyRoversPosition modifyRoversPosition, string commands)
        {
            try
            {
                foreach (char item in commands)
                {
                    string      actionString = item.ToString();
                    RoverAction roverAction  = RoverAction.N;

                    Enum.TryParse <RoverAction>(actionString, true, out roverAction);

                    ICommand roverCommand = new RoverCommand(rover, Creator.GetAction(roverAction));
                    modifyRoversPosition.SetCommand(roverCommand);
                    modifyRoversPosition.Invoke();
                }
            }
            catch (MovementException mEx)
            {
                Console.WriteLine(ExceptionHelper.GetExceptionMessage(mEx));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ExceptionHelper.GetExceptionMessage(ex));
            }
        }
        public void DirectionsTest()
        {
            var roverCommand = new RoverCommand();
            var res          = roverCommand.Directions("N");

            Assert.Equal(Direction.N, res);
        }
Beispiel #4
0
 private ICommandProcessor CreateCommandProcessor(RoverCommand command)
 {
     return(command switch
     {
         RoverCommand.Move => new MoveForwardCommandProcess(),
         RoverCommand.Left => new RotateLeftCommandProcess(),
         RoverCommand.Right => new RotateRightCommandProcess(),
         _ => throw new MarsRoversValidationException("ProcessCommand", $"Invalid rover command {command}")
     });
 public void GetPositionsRoverTest()
 {
     using (var sr = new StringReader("1 2 N" + Environment.NewLine + "LMLMLMLMM"))
     {
         Console.SetIn(sr);
         var roverCommand = new RoverCommand();
         var res          = roverCommand.GetPositionsRover();
         Assert.True(res);
     }
 }
 public void GetPlateauTest()
 {
     using (var sr = new StringReader("5 5"))
     {
         Console.SetIn(sr);
         var roverCommand = new RoverCommand();
         var res          = roverCommand.GetPlateau();
         Assert.True(res);
     }
 }
        public void Command_Does_Exceeding_The_Limit_Of_Location_Should_Throw_Invalid_Operation_Exception(int locationWidth, int locationHeight, int startX, int startY, Direction direction, string command)
        {
            var roverCommand = new RoverCommand(command);
            var rover        = new Rover();

            rover.Initialize(new Location(locationWidth, locationHeight), new Coordinate {
                X = startX, Y = startY
            }, direction);
            roverCommand.SetReceiver(rover);
            Assert.Throws <InvalidOperationException>(() => roverCommand.Execute(), "Rover Can not exceed the given location");
        }
Beispiel #8
0
        public void ExecuteCommand(RoverCommand command)
        {
            switch (command)
            {
            case RoverCommand.Move: Move(); break;

            case RoverCommand.RotateLeft: Rotate(false); break;

            case RoverCommand.RotateRight: Rotate(true); break;
            }
        }
        public void GetMoveListTest()
        {
            List <string> moveList = new List <string>();

            moveList.Add("L");
            moveList.Add("M");
            moveList.Add("L");
            moveList.Add("M");
            moveList.Add("L");
            moveList.Add("M");
            moveList.Add("L");
            moveList.Add("M");
            moveList.Add("M");
            var    roverCommand = new RoverCommand();
            IRover rover        = new Rover();

            rover.Position.coordinates.X = 1;
            rover.Position.coordinates.Y = 2;
            rover.Position.direction     = Direction.N;
            var res = roverCommand.GetMoveList("LMLMLMLMM", rover);

            Assert.Equal(moveList, res);
        }
Beispiel #10
0
        public Position ProcessCommand(RoverCommand command, Position position)
        {
            var processor = CreateCommandProcessor(command);

            return(processor.ProcessCommand(position));
        }
Beispiel #11
0
 public MarsRoberFixture()
 {
     Map.MaxXCoordinate = 5;
     Map.MaxYCoordinate = 5;
     _roberCommand      = new RoverCommand();
 }
Beispiel #12
0
 public RoberCommandFixture()
 {
     Map.MaxXCoordinate = 5;
     Map.MaxYCoordinate = 5;
     _command           = new RoverCommand();
 }