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; } } }
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(); }
public void ExecuteBatchCmds_UnknownCmd_UnknownCmdException() { // Arrange var rover = Rover.CreateRover("5 5 N"); // Act rover.ExecuteBatchCmds("S"); }
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)); } }
public void CreateRover_WrongCardinal_WrongRoverDefinitionException() { // Act Rover.CreateRover("5 5 H"); }
public void CreateRover_NoIntXY_WrongRoverDefinitionException() { // Act Rover.CreateRover("N N N"); }
public void CreateRover_EmptyDefinition_WrongRoverDefinitionException() { // Act Rover.CreateRover(""); }