Пример #1
0
        public void PrepareRover(RoverModel model)
        {
            if (model.ErrorTracer == null)
            {
                _rover           = Rover.CreateRover(this);
                _rover.X         = model.X;
                _rover.Y         = model.Y;
                _rover.Direction = EnumConvertor.ConvertCharToDirection(model);
                _rover.Plateau   = _plateaus;

                if (model.X < 0 || model.X < 0)
                {
                    _rover.ErrorMessage = MessageConstant.RoverPlateauCoordinateFail;
                }


                if (model.Plateau.UpperRight < model.X || model.Plateau.LowerLeft < model.X)
                {
                    _rover.ErrorMessage = MessageConstant.RoverPlateauCoordinateFail;
                }

                if (model.Plateau.UpperRight < model.Y || model.Plateau.LowerLeft < model.Y)
                {
                    _rover.ErrorMessage = MessageConstant.RoverPlateauCoordinateFail;
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            const string fileName = "BulkDeploy.txt";

            using (var streamReader = File.OpenText(fileName))
            {
                var line = streamReader.ReadLine();

                if (line != null)
                {
                    var   plateau = Plateau.CreatePlateau(line);
                    var   count   = 0;
                    Rover rover   = null;

                    while ((line = streamReader.ReadLine()) != null)
                    {
                        if (count % 2 == 0)
                        {
                            rover = Rover.CreateRover(line);
                            rover.SetPlateau(plateau);
                        }
                        else
                        {
                            rover.ExecuteBatchCmds(line);
                            Console.WriteLine(rover.GetPosition());
                        }

                        count++;
                    }
                }
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Пример #3
0
        public void ExecuteBatchCmds_UnknownCmd_UnknownCmdException()
        {
            // Arrange
            var rover = Rover.CreateRover("5 5 N");

            // Act
            rover.ExecuteBatchCmds("S");
        }
Пример #4
0
 public HttpResponseMessage DeployRover([FromBody]  RoverConfig roverconfig)
 {
     try
     {
         Rover rover   = null;
         var   plateau = Plateau.CreatePlateau(roverconfig.Plateau);
         rover = Rover.CreateRover(roverconfig.StartPosition);
         rover.SetPlateau(plateau);
         rover.ExecuteBatchCmds(roverconfig.MoveCommands);
         return(Request.CreateResponse(HttpStatusCode.Created, rover.GetPosition()));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message: ex.Message));
     }
 }
Пример #5
0
 public void CreateRover_WrongCardinal_WrongRoverDefinitionException()
 {
     // Act
     Rover.CreateRover("5 5 H");
 }
Пример #6
0
 public void CreateRover_NoIntXY_WrongRoverDefinitionException()
 {
     // Act
     Rover.CreateRover("N N N");
 }
Пример #7
0
 public void CreateRover_EmptyDefinition_WrongRoverDefinitionException()
 {
     // Act
     Rover.CreateRover("");
 }