Пример #1
0
        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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        //[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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
 private void Start()
 {
     player = RoverManager.instance.rover.GetComponent <RoverMovement>();
 }
Пример #14
0
 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);
 }