예제 #1
0
        public void GetRoverCoordinatesFromApiTest()
        {
            int              recordCount          = 0;
            string           RoverNavigationInput = "5 5\r\n1 2 N\r\nLMLMLMLMM";
            RoverOutputModel expectedResult       = new RoverOutputModel()
            {
                PositionX = 1, PositionY = 3, Heading = "N"
            };

            using (var container = builder.Build())
            {
                var RoverNavigationService = container.Resolve <IRoverNavigationService>();
                var model = RoverNavigationService.GetRoverCoordinates(RoverNavigationInput);
                recordCount = model.Count;
                if (model != null && model.Count > 0)
                {
                    var result = model[0];
                    Assert.AreEqual(expectedResult.PositionX, result.PositionX);
                    Assert.AreEqual(expectedResult.PositionY, result.PositionY);
                    Assert.AreEqual(expectedResult.Heading, result.Heading);
                }
            }
        }
예제 #2
0
 public RoverInputModel()
 {
     Position = new RoverOutputModel();
 }
예제 #3
0
        /// <summary>
        /// Processes the navigation instructions
        /// </summary>
        /// <param name="RoverInputCommand"></param>
        /// <returns></returns>
        private RoverOutputModel ExecuteCommand(RoverInputModel RoverInputCommand)
        {
            var commands = RoverInputCommand.Instructions.ToCharArray();
            RoverOutputModel finalCoodinates = new RoverOutputModel();

            foreach (char command in commands)
            {
                switch (command)
                {
                case 'L':
                    switch (RoverInputCommand.Position.Heading)
                    {
                    case "E":
                        RoverInputCommand.Position.Heading = "N";
                        break;

                    case "N":
                        RoverInputCommand.Position.Heading = "W";
                        break;

                    case "W":
                        RoverInputCommand.Position.Heading = "S";
                        break;

                    case "S":
                        RoverInputCommand.Position.Heading = "E";
                        break;
                    }
                    break;

                case 'R':
                    switch (RoverInputCommand.Position.Heading)
                    {
                    case "E":
                        RoverInputCommand.Position.Heading = "S";
                        break;

                    case "N":
                        RoverInputCommand.Position.Heading = "E";
                        break;

                    case "W":
                        RoverInputCommand.Position.Heading = "N";
                        break;

                    case "S":
                        RoverInputCommand.Position.Heading = "W";
                        break;
                    }
                    break;

                case 'M':
                    RoverInputCommand = Move(RoverInputCommand);
                    break;
                }
            }

            finalCoodinates.PositionX = RoverInputCommand.Position.PositionX;
            finalCoodinates.PositionY = RoverInputCommand.Position.PositionY;
            finalCoodinates.Heading   = RoverInputCommand.Position.Heading;

            return(finalCoodinates);
        }