/// <summary> /// Konumlanma koordinatlarının platoya göre kontrolü /// </summary> /// <param name="plateau"></param> /// <param name="deploymentPoint"></param> private void CheckDeploymentPoint(PlateauModel plateau, DeploymentPointModel deploymentPoint) { if (plateau.Width < deploymentPoint.X || plateau.Height < deploymentPoint.Y || deploymentPoint.X < 0 || deploymentPoint.Y < 0) { throw new OutOfBoundsFromPlateauException("Rover can't located on plateau."); } }
public bool Move(PlateauModel plateau, RoverModel rover) { if (!CanItMove(plateau, rover)) { return(false); } switch (rover.Direction) { case DirectionEnum.N: rover.CurrentYCoordinate += 1; break; case DirectionEnum.E: rover.CurrentXCoordinate += 1; break; case DirectionEnum.S: rover.CurrentYCoordinate -= 1; break; case DirectionEnum.W: rover.CurrentXCoordinate -= 1; break; } return(true); }
private bool MoveCheck(PlateauModel plateau, RoverModel rover) { return((rover.XCoord >= 0) && (rover.XCoord <= plateau.Width) && (rover.YCoord >= 0) && (rover.YCoord <= plateau.Height)); }
/// <summary> /// İstenilen yönüne göre hareket eylemine yönlendirir. /// </summary> /// <param name="rover"></param> /// <param name="plateau"></param> /// <returns></returns> private RoverModel Move(RoverModel rover, PlateauModel plateau) { foreach (var movingDirection in rover.Movement.MovementList) { switch (movingDirection) { case MovementAbility.L: MoveLeft(rover); break; case MovementAbility.R: MoveRight(rover); break; case MovementAbility.M: MoveStraight(rover, plateau); break; default: throw new InvalidMovementAbilityParamException("Invalid moving key for rover"); } } return(rover); }
public void CalculateRoverMovement_Success_TaskInput2(string calculationCommand) { // Arrange var plataue = new PlateauModel(5, 5); //Act var rover = _roverService.SetRoverOnPlateau(plataue, new DeploymentPointModel(Direction.E.ToString()) { X = 3, Y = 3 }); var movements = calculationCommand .ToCharArray() .Select(x => Enum.Parse <MovementAbility>(x.ToString())) .ToList(); rover.Movement.MovementList = movements; _roverService.CalculateRoverMovement(rover, plataue); //Assert Assert.NotNull(plataue); Assert.NotNull(rover.Movement.MovementList); Assert.Equal(5, rover.DeploymentPoint.X); Assert.Equal(1, rover.DeploymentPoint.Y); Assert.Equal(Direction.E, rover.DeploymentPoint.Direction); }
private static bool IsValid(RoverPositionModel roverPositionModel, PlateauModel plateauModel) { var isValidX = roverPositionModel.X >= 0 && roverPositionModel.X <= plateauModel.Width; var isValidY = roverPositionModel.Y >= 0 && roverPositionModel.Y <= plateauModel.Height; return(isValidX && isValidY); }
public async Task GivenTheCommandIsValidWhenMoveRoverIsCalledThenRoverPositionIsChanged(string command) { //Arrange var arrangedPosition = new PositionModel { XPos = 3, YPos = 3, Direction = Model.Enums.Direction.N }; var plateauModel = new PlateauModel { Height = 5, Width = 5 }; var expectedPosition = new PositionModel { XPos = 2, YPos = 3, Direction = Model.Enums.Direction.S }; var roverMovementService = new RoverMovementService(plateauService); //Act var response = await roverMovementService.MoveRover(command, arrangedPosition, plateauModel); //Assert Assert.AreEqual(expectedPosition.XPos, response.XPos); Assert.AreEqual(expectedPosition.YPos, response.YPos); Assert.AreEqual(expectedPosition.Direction, response.Direction); }
/// <summary> /// Plateau and Coord control function /// </summary> /// <param name="plateauInput"></param> /// <returns>true: OK ,false : Coordinate Error </returns> private bool PlateauCoordControl(PlateauModel plateauInput) { if (XCoord < 0 || XCoord > plateauInput.Width || YCoord < 0 || YCoord > plateauInput.Height) { return(false); } return(true); }
/// <summary> /// Gezicinin plato üzerinde hareketini hesaplar. /// </summary> /// <param name="rover"></param> /// <param name="plateau"></param> /// <returns></returns> public RoverModel CalculateRoverMovement(RoverModel rover, PlateauModel plateau) { if (rover == null) { throw new BadRequestException("Please check your requested Rover Model."); } return(Move(rover, plateau)); }
public string CalculatePosition(PlateauModel plateau, RoverModel rover, string order) { for (int i = 0; i < order.Length; i++) { rover = Execute(plateau, rover, order[i]); } return($"{rover.XCoord} {rover.YCoord} {rover.Direction}"); }
public void DrawPlateau_InvalidRangeException_WhenPointsIsNull(int width, int height) { // Act var plataeu = new PlateauModel(width, height); var action = new Action(() => _plateauService.DrawPlateau(plataeu)); // Assert Assert.Throws <InvalidParameterOfPlateauException>(action); }
static void Main(string[] args) { Console.WriteLine("Mission started."); // create service collection RegisterServices(); var roverService = _serviceProvider.GetService <IRoverService>(); bool IsContinue; Console.WriteLine("Please enter the upper-right coordinates of the plateau.(Format=X Y)"); Console.WriteLine("Info: Consider that the lower-left coordinates are assumed to be 0,0"); string upperRightCoordinates = Console.ReadLine(); var _plateauCoordinates = upperRightCoordinates.Split(" "); do { Console.WriteLine("Please enter the current coordinates and direction(N/E/S/W). (Format=X Y D)"); string currentCoordinates = Console.ReadLine(); var _currentCoordinates = currentCoordinates.Split(" "); Enum.TryParse(_currentCoordinates[2], out DirectionEnum _direction); Console.WriteLine("Please enter the your intsructions. (L=left, R=right, M=Move)"); string command = Console.ReadLine(); var plateau = new PlateauModel(Convert.ToInt32(_plateauCoordinates[0]), Convert.ToInt32(_plateauCoordinates[1])); var rover = new RoverModel(Convert.ToInt32(_currentCoordinates[0]), Convert.ToInt32(_currentCoordinates[1]), _direction, command); var response = roverService.Run(plateau, rover); if (!response.HasError) { Console.WriteLine($"Current location info: {response.Data.CurrentXCoordinate} {response.Data.CurrentYCoordinate} {response.Data.Direction}"); Console.WriteLine("Do you want to move new rover? (Y/N)"); string moveNewRover = Console.ReadLine(); if (moveNewRover.ToUpper() == "Y") { IsContinue = true; } else { IsContinue = false; } } else { Console.WriteLine($"{response.Errors}"); IsContinue = false; } } while (IsContinue); Console.WriteLine("Mission completed."); DisposeServices(); }
/// <summary> /// Platonun oluşturulmasını sağlar. /// </summary> /// <param name="model"></param> /// <returns></returns> public PlateauModel DrawPlateau(PlateauModel model) { if (model.Width == 0 || model.Height == 0) { throw new InvalidParameterOfPlateauException("Invalid parameters for drawing plataeu area"); } return(model); }
/// <summary> /// Gezicinin plato üzerine konumlanmasını sağlar. /// </summary> /// <param name="plateau"></param> /// <param name="deploymentPoint"></param> /// <returns></returns> public RoverModel SetRoverOnPlateau(PlateauModel plateau, DeploymentPointModel deploymentPoint) { CheckDeploymentPoint(plateau, deploymentPoint); CheckDirection(deploymentPoint.Direction); return(new RoverModel() { DeploymentPoint = deploymentPoint }); }
public void DrawPlateau_Success_WhenCorrectParams(int width, int height) { // Act var plataeu = new PlateauModel(width, height); //Assert Assert.Equal(plataeu.Width, width); Assert.Equal(plataeu.Height, height); }
public static PlateauModel ParsePlateauOrigin() { var plateuOrigin = ParseWithSpace(allCommandsLine[0]); var response = new PlateauModel(); var origins = ConvertOrigin(plateuOrigin); response.PlateauMaxX = origins.Item1; response.PlateauMaxY = origins.Item2; return(response); }
public bool IsRoverInsidePlateau(RoverPositionModel roverPosition, PlateauModel plateau) { bool isInside = false; if (roverPosition.X < plateau.X || roverPosition.Y < plateau.Y) { isInside = true; } return(isInside); }
public PlateauService(string command) { if (_plateauModel == null) { _plateauModel = new PlateauModel(); } _plateauModel.Width = Convert.ToInt32(command.Split(" ")[0]) > 0 ? Convert.ToInt32(command.Split(" ")[0]) : throw new Exception(); _plateauModel.Height = Convert.ToInt32(command.Split(" ")[1]) > 0 ? Convert.ToInt32(command.Split(" ")[1]) : throw new Exception(); }
public void RoverFinalPosition_ShouldReturnExpectedValue_WhenInstructionsAreSet() { PlateauModel plateau = new PlateauModel(5, 5); RoverModel rover = new RoverModel(1, 2, "N"); string order = "LMLMLMLMM"; var roverActionService = new RoverActionService(); var actual = roverActionService.CalculatePosition(plateau, rover, order); Assert.Equal("1 3 N", actual); }
private static void GetInputsForPlateau(PlateauModel plateaus, IManager manager) { do { manager.PreparePlateau(plateaus); if (plateaus.ErrorTracer != null) { Console.WriteLine(plateaus.ErrorTracer); } } while (plateaus.ErrorTracer != null); }
public void SendToPlateau(LandBase plateau) { var readonlyDictionary = plateau.Rovers.ToDictionary(rover => rover.Id, rover => new KeyValuePair <int, int>(rover.Point.XPosition, rover.Point.YPosition)); Plateau = PlateauModel.CreateNew(readonlyDictionary, plateau.Size, plateau.Id, plateau.Name); PlateauId = Plateau.PlateauId; if (!Plateau.IsValidPoint(Point)) { throw new InvalidPositionException(); } }
public void Setup() { var fix = new PlateauModel { Height = 5, Width = 5 }; var mockPlateauService = new Mock <IPlateauService>(); mockPlateauService.Setup(x => x.GetPlateau()).Returns(fix); plateauService = mockPlateauService.Object; }
static void Main(string[] args) { #region Parameters var plateau = new PlateauModel(); plateau.LowerLeft = 5; plateau.UpperRight = 5; var rover1 = new RoverModel { X = 1, Y = 2, Direction = 'N', Movement = "LMLMLMLMM", Plateau = plateau }; var rover2 = new RoverModel { X = 3, Y = 3, Direction = 'E', Movement = "MMRMMRMRRM", Plateau = plateau }; #endregion Queue <RoverModel> myQueue = new Queue <RoverModel>(); myQueue.Enqueue(rover1); myQueue.Enqueue(rover2); Manager manager = new Manager(); GetInputsForPlateau(plateau, manager); manager.PreparePlateau(plateau); string roverStatus = ""; int i = 1; while (myQueue.Count > 0) { var rover = myQueue.Dequeue(); GetInputsForRover(rover, manager, plateau, i); roverStatus += manager.GetRoverStatus(); i++; } Console.WriteLine(roverStatus); Console.ReadLine(); }
public Task <string> Handle(CalculateFinalPositionCommand request, CancellationToken cancellationToken) { var plateauCoordinates = request.PlateauCoordinates.Split(" ").ToList(); var roverPosition = request.RoverPosition.Split(" ").ToList(); PlateauModel plateau = new PlateauModel(Convert.ToInt32(plateauCoordinates[0]), Convert.ToInt32(plateauCoordinates[1])); RoverModel rover = new RoverModel(Convert.ToInt32(roverPosition[0]), Convert.ToInt32(roverPosition[1]), roverPosition[2]); return(Task.Run(() => { return _roverActionService.CalculatePosition(plateau, rover, request.RoverOrder); })); }
public void Create_Zero_Plateau() { var model = new PlateauModel(); model.LowerLeft = 0; model.UpperRight = 0; _manager.PreparePlateau(model); var result = _manager.PlateausInstance.ErrorMessage; var exceptedResult = MessageConstant.PlateauLimitsFail; Assert.Equal(exceptedResult, result); }
public void Create_Valid_Plateau() { var model = new PlateauModel(); model.LowerLeft = 10; model.UpperRight = 5; _manager.PreparePlateau(model); var result = model.ErrorTracer; Assert.Null(result); }
private static void GetInputsForRover(RoverModel rover, IManager manager, PlateauModel plateaus, int i) { do { manager.PrepareRover(rover); if (rover.ErrorTracer != null) { Console.WriteLine(rover.ErrorTracer); } } while (rover.ErrorTracer != null); GetInputForPath(rover, manager); }
public void Create_Invalid_Plateau() { var model = new PlateauModel(); model.LowerLeft = -1; model.UpperRight = -1; _manager.PreparePlateau(model); var result = model.ErrorTracer; var exceptedResult = MessageConstant.PlateauLimitsFail; Assert.NotEqual(exceptedResult, result); }
public void SetRoverOnPlateau_InvalidDirectionException_WhenDirectionIsInvalid(int expectedX, int expectedY, string expectedDirection) { // Arrange var plataue = new PlateauModel(10, 10); // Act var action = new Action(() => _roverService.SetRoverOnPlateau(plataue, new DeploymentPointModel(expectedDirection) { X = expectedX, Y = expectedY })); // Assert Assert.Throws <InvalidDirectionException>(action); }
public void PreparePlateau(PlateauModel model) { if (model.ErrorTracer == null) { _plateaus = Plateau.CreatePlateau(this); if (model.UpperRight <= 0 && model.LowerLeft <= 0) { _plateaus.ErrorMessage = MessageConstant.PlateauLimitsFail; } _plateaus.LowerLeft = model.LowerLeft; _plateaus.UpperRight = model.UpperRight; } }