public IActionResult MoveRover(RoverViewModel roverViewModel) { var _roverMovement = new RoverMovement(roverViewModel); try { _roverMovement.ValidatePlateau(); } catch (Exception ex) { roverViewModel.Error = ex.Message; return(View("Index", roverViewModel)); } try { _roverMovement.Navigate(roverViewModel.Rover1); } catch (Exception ex) { roverViewModel.Error = string.Concat("Rover 1: ", ex.Message); return(View("Index", roverViewModel)); } try { _roverMovement.Navigate(roverViewModel.Rover2); } catch (Exception ex) { roverViewModel.Error = string.Concat("Rover 2: ", ex.Message); } return(View("Index", roverViewModel)); }
public void RoverMovement_ShouldArgumentException_WhenPositionIsNull() { var testRoverRequest = new TestRoverRequest { TopPositionX = 5, TopPositionY = 5, CurrentX = 1, CurrentY = 2, CurrentFacing = "N", Direction = "", ExpectedFace = "N", ExpectedXCoordinate = 1, ExpectedYCoordinate = 3 }; var roverMovement = new RoverMovement(); var result = Record.Exception(() => roverMovement.RoverMove(testRoverRequest)); Assert.NotNull(result); var exception = Assert.IsType <ArgumentException>(result); var actual = exception.Message; const string expectedErrorMessage = "Direction cannot be null or empty."; Assert.Equal(expectedErrorMessage, actual); }
//[DataRow(0, 3, 2, 5)] //[DataRow(2, 6, 3, 3)] //[DataRow(7, 3, 1, 1)] //[DataRow(0, 0, 5, 0)] public void CheckRoverPositionTest_NotAllowedPositions(int lon1, int lat1, int lon2, int lat2) { _roverModel.PlateauSizeLongitude = 5; _roverModel.PlateauSizeLatitude = 5; _roverModel.Rover1.Position.Longitude = lon1; _roverModel.Rover1.Position.Latitude = lat1; _roverModel.Rover2.Position.Longitude = lon2; _roverModel.Rover2.Position.Latitude = lat2; _roverMovement = new RoverMovement(_roverModel); bool valid = false; try { valid = _roverMovement.CheckRoverPositionsAllowed(); } catch (System.Exception) { } Assert.IsFalse(valid); }
public void RoverMovement_ShouldArgumentNullException_WhenTopPositionYIsNull() { var testRoverRequest = new TestRoverRequest { TopPositionX = 5, TopPositionY = 0, CurrentX = 1, CurrentY = 2, CurrentFacing = "N", Direction = "LMLMLMLMM", ExpectedFace = "N", ExpectedXCoordinate = 1, ExpectedYCoordinate = 3 }; var roverMovement = new RoverMovement(); var result = Record.Exception(() => roverMovement.RoverMove(testRoverRequest)); Assert.NotNull(result); var exception = Assert.IsType <ArgumentNullException>(result); var actual = exception.ParamName; const string expectedErrorMessage = "TopPositionY with value 0 should be more than zero."; Assert.Equal(expectedErrorMessage, actual); }
public void RoverMovement_ValidObjectPassed_ReturnedResponseModel(TestRoverRequest testRoverRequest) { var roverMovement = new RoverMovement(); var responseModel = roverMovement.RoverMove(testRoverRequest); Assert.IsType <TestRoverRequest>(testRoverRequest); Assert.Equal(testRoverRequest.ExpectedFace, responseModel.Position.Face); Assert.Equal(testRoverRequest.ExpectedXCoordinate, responseModel.Position.xCoordinate); Assert.Equal(testRoverRequest.ExpectedYCoordinate, responseModel.Position.yCoordinate); }
public void CheckPlateauHasDimensions_positive(int lonSize, int latSize) { _roverModel.PlateauSizeLongitude = lonSize; _roverModel.PlateauSizeLatitude = latSize; _roverMovement = new RoverMovement(_roverModel); var valid = _roverMovement.MatrixHasDimensions(); Assert.IsTrue(valid); }
public void ValidateStartingPosition_invalidYValue_ShouldThrowFormatException() { //this test method is for testing invalid inputs of x,y or orientation RoverMovement obj = new RoverMovement(); //test y string input0 = " 5 5"; string[] UpperRightCoordinates = input0.Split(' '); string input1 = " 3 ! N"; string[] StartingPositionArray = input1.Split(' '); obj.ValidateStartingPosition(StartingPositionArray, UpperRightCoordinates); }
public void CheckRoverPositionTest_AllowedPositions(int lon1, int lat1, int lon2, int lat2) { _roverModel.PlateauSizeLongitude = 5; _roverModel.PlateauSizeLatitude = 5; _roverModel.Rover1.Position.Longitude = lon1; _roverModel.Rover1.Position.Latitude = lat1; _roverModel.Rover2.Position.Longitude = lon2; _roverModel.Rover2.Position.Latitude = lat2; _roverMovement = new RoverMovement(_roverModel); var valid = _roverMovement.CheckRoverPositionsAllowed(); Assert.IsTrue(valid); }
public void ProcessInstruction_ChangesHeading_N() { _roverModel.PlateauSizeLongitude = 5; _roverModel.PlateauSizeLatitude = 5; _roverModel.Rover1.Position.Longitude = 1; _roverModel.Rover1.Position.Latitude = 1; _roverModel.Rover1.Position.Heading = Heading.E; _roverModel.Rover1.Instructions = "N"; _roverMovement = new RoverMovement(_roverModel); _roverMovement.Navigate(_roverModel.Rover1); Assert.IsTrue(_roverModel.Rover1.Position.Heading == Heading.N); }
public void CheckPlateauHasDimensions_negative(int lonSize, int latSize) { _roverModel.PlateauSizeLongitude = lonSize; _roverModel.PlateauSizeLatitude = latSize; _roverMovement = new RoverMovement(_roverModel); bool valid = false; try { valid = _roverMovement.MatrixHasDimensions(); } catch (System.Exception) { } Assert.IsFalse(valid); }
public void ProcessInstruction_ChangesPosition_11E() { _roverModel.PlateauSizeLongitude = 5; _roverModel.PlateauSizeLatitude = 5; _roverModel.Rover1.Position.Longitude = 1; _roverModel.Rover1.Position.Latitude = 1; _roverModel.Rover1.Position.Heading = Heading.E; _roverModel.Rover1.Instructions = "M"; _roverMovement = new RoverMovement(_roverModel); _roverMovement.Navigate(_roverModel.Rover1); Assert.IsTrue(_roverModel.Rover1.Position.Heading == Heading.E); Assert.AreEqual(2, _roverModel.Rover1.Position.Longitude); Assert.AreEqual(1, _roverModel.Rover1.Position.Latitude); }
public void RoverMovement_ShouldSuccess_WhenDirectionIsLowercase() { var testRoverRequest = new TestRoverRequest { TopPositionX = 5, TopPositionY = 5, CurrentX = 1, CurrentY = 2, CurrentFacing = "N", Direction = "lmlmlmlmm", ExpectedFace = "N", ExpectedXCoordinate = 1, ExpectedYCoordinate = 3 }; var roverMovement = new RoverMovement(); var responseModel = roverMovement.RoverMove(testRoverRequest); Assert.IsType <TestRoverRequest>(testRoverRequest); Assert.Equal(testRoverRequest.ExpectedFace, responseModel.Position.Face); Assert.Equal(testRoverRequest.ExpectedXCoordinate, responseModel.Position.xCoordinate); Assert.Equal(testRoverRequest.ExpectedYCoordinate, responseModel.Position.yCoordinate); }
private void Start() { player = RoverManager.instance.rover.GetComponent <RoverMovement>(); }
public void MoveRover(RoverMovement movement) { // Invia una notifica SignalR con il comando di movimento del Rover. sensorHub.Value.Clients.Group(SensorHub.DEVICES_GROUP).MoveRover(movement); }