Пример #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 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);
        }
Пример #3
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);
        }