public ServiceResult <Plateau> AddNewRover(Plateau plateau, int roverX, int roverY, char direction) { ServiceResult <Plateau> result = new ServiceResult <Plateau>(); try { Coordinate startCoordinate = new Coordinate(roverX, roverY); Direction startDirection = DirectionCreator.Create(direction); if (startDirection == null) { result.ErrorMessage = $"Start direction parameter is invalid. Param value:{direction}"; result.ResultStatus = ServiceResultStatus.NotValid; logger.ErrorLog(new ServiceException(result.ErrorMessage), result.ErrorMessage); } else { plateau = plateauOperations.AddNewRover(plateau, startCoordinate, startDirection); result.Response = plateau; } } catch (Exception ex) { result.ResultStatus = ServiceResultStatus.Failed; result.ErrorMessage = $"AddNewRover function error: Please check your input. x:{roverX}, y:{roverY}, d:{direction}"; logger.ErrorLog(ex, result.ErrorMessage); } return(result); }
public void AddNewRoverSuccessTest(int roverX, int roverY, char roverD) { Plateau plateau = new Plateau(new Coordinate(50, 50)); Assert.IsNotNull(plateau); Assert.IsNotNull(plateau.Rovers); Coordinate coordinate = new Coordinate(roverX, roverY); Direction direction = DirectionCreator.Create(roverD); plateau = plateauOperations.AddNewRover(plateau, coordinate, direction); Assert.IsNotNull(plateau); Assert.IsNotNull(plateau.SelectedRover); Assert.IsNotNull(plateau.SelectedRover.CurrentCoordinate); Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.X >= plateau.MinX && plateau.SelectedRover.CurrentCoordinate.X <= plateau.MaxX); Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.Y >= plateau.MinY && plateau.SelectedRover.CurrentCoordinate.Y <= plateau.MaxY); Assert.AreSame(plateau.SelectedRover.CurrentCoordinate, coordinate); }
public void ExecuteBatchCommandSuccessTest(int plateauUpperRightX, int plateauUpperRightY, int roverX, int roverY, char roverD, string command, int expectedRoverX, int expectedRoverY, int expectedRoverD) { Plateau plateau = new Plateau(new Coordinate(plateauUpperRightX, plateauUpperRightY)); Assert.IsNotNull(plateau); Assert.IsNotNull(plateau.Rovers); Coordinate coordinate = new Coordinate(roverX, roverY); Direction direction = DirectionCreator.Create(roverD); plateau = plateauOperations.AddNewRover(plateau, coordinate, direction); Assert.IsNotNull(plateau); Assert.IsNotNull(plateau.SelectedRover); Assert.IsNotNull(plateau.SelectedRover.CurrentCoordinate); Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.X >= plateau.MinX && plateau.SelectedRover.CurrentCoordinate.X <= plateau.MaxX); Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.Y >= plateau.MinY && plateau.SelectedRover.CurrentCoordinate.Y <= plateau.MaxY); Assert.AreSame(plateau.SelectedRover.CurrentCoordinate, coordinate); plateau = roverOperations.ExecuteBatchCommand(plateau.SelectedRover, command); Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.X, expectedRoverX); Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.Y, expectedRoverY); Assert.AreEqual(plateau.SelectedRover.Direction, expectedRoverD); }