Beispiel #1
0
        public override void Move(int step)
        {
            int newY = 0;
            int newX = 0;

            try
            {
                switch (this.Orientation)
                {
                case Orientation.N:
                    newY = this.CurrPosition.Y + step;
                    this.CurrPosition.Y = RoverHelper.MoveOnY(newY, this.Landscape.Y);
                    break;

                case Orientation.S:
                    newY = this.CurrPosition.Y - step;
                    this.CurrPosition.Y = RoverHelper.MoveOnY(newY, this.Landscape.Y);
                    break;

                case Orientation.E:
                    newX = this.CurrPosition.X + step;
                    this.CurrPosition.X = RoverHelper.MoveOnX(newX, this.Landscape.X);
                    break;

                case Orientation.W:
                    newX = this.CurrPosition.X - step;
                    this.CurrPosition.X = RoverHelper.MoveOnX(newX, this.Landscape.X);
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Execute command failed - " + ex.Message);
            }
        }
Beispiel #2
0
        public void ReturnSameOutput(string inputPath, string outputPath)
        {
            string input    = File.ReadAllText(inputPath, Encoding.UTF8);
            string expected = File.ReadAllText(outputPath, Encoding.UTF8);

            string actual = RoverHelper.StartInstructions(input);

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
 public void RemoveRepeatedSteps_ZeroLengthCommandList_ReturnEmptyList()
 {
     //Arrange
     char[] commands = "".ToCharArray();
     //Action
     char[] result = RoverHelper.RemoveRepeatedSteps(commands);
     //Assert
     Assert.Empty(result);
 }
Beispiel #4
0
 public void RemoveRepeatedSteps_CommandsListContainsRepetatedSteps_ReturnWithoutRepeteadSteps()
 {
     //Arrange
     char[] commands = "RRRRMMLLLLRRMRMRMRMMMLMRLMLMLMLM".ToCharArray();
     char[] expected = "MMRMMLMR".ToCharArray();
     //Action
     char[] result = RoverHelper.RemoveRepeatedSteps(commands);
     //Assert
     Assert.Equal(expected, result);
 }
Beispiel #5
0
 public void RemoveRepeatedSteps_RotateCommandsParameter_ReturnWithoutRotateParameters()
 {
     //Arrange
     char[] commands = "RRRRMMLLLLRR".ToCharArray();
     char[] expected = "MMRR".ToCharArray();
     //Action
     char[] result = RoverHelper.RemoveRepeatedSteps(commands);
     //Assert
     Assert.Equal(expected, result);
 }
Beispiel #6
0
        public ActionResult <string> Get(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(BadRequest("Input parameter is not a valid string"));
            }

            string output = RoverHelper.StartInstructions(input);

            return(Ok(output));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            string path;

            path = GetPath(args);

            string input = File.ReadAllText(path, Encoding.UTF8);

            string output = RoverHelper.StartInstructions(input);

            Console.WriteLine(output);
        }
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Welcome to the Mars...\n");

                var plateau = PlateauHelper.RetrievePlateauSizeAndCreatePlateau();

                var rover = RoverHelper.RetrieveRoverPropertiesAndCreateRover(plateau);
                ControlRoverAndWriteLastPosition(rover);

                var rover2 = RoverHelper.RetrieveRoverPropertiesAndCreateRover(plateau);
                ControlRoverAndWriteLastPosition(rover2);

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                return;
            }
        }
 public Rover parse(Rover rover, String roverInput, String maxPos)
 {
     return(RoverHelper.moveRover(rover, roverInput, maxPos));
 }
Beispiel #10
0
 public void execute(Rover rover, String maxPos)
 {
     RoverHelper.moveAhead(rover, maxPos);
 }
Beispiel #11
0
 public void execute(Rover rover, String maxPos)
 {
     RoverHelper.rotateRight(rover, maxPos);
 }