Esempio n. 1
0
 public void When_Command_Exceeds_The_Limits()
 {
     result       = new Result();
     rover        = new Rover(new Position(3, 3), Direction.N);
     roverService = new RoverService(rover, new Plateau(5, 5, new Result()), new Result());
     roverService.Process("MMMMMMMMMMR");
     Assert.AreEqual(roverService.GetCurrentLocation(), "3 5 E");
 }
Esempio n. 2
0
 public void Rover_Check_Location_Success()
 {
     result       = new Result();
     rover        = new Rover(new Position(1, 1), Direction.N);
     roverService = new RoverService(rover, new Plateau(5, 5, new Result()), new Result());
     roverService.Process("MRML");
     Assert.AreEqual(roverService.GetCurrentLocation(), "2 2 N");
 }
Esempio n. 3
0
 public void Second_Rover_Check_Location_Success()
 {
     result       = new Result();
     rover        = new Rover(new Position(3, 3), Direction.E);
     roverService = new RoverService(rover, new Plateau(5, 5, new Result()), new Result());
     roverService.Process("MMRMMRMRRM");
     Assert.AreEqual(roverService.GetCurrentLocation(), "5 1 E");
 }
Esempio n. 4
0
        public void First_Rover_Check_Location_Error()
        {
            result       = new Result();
            rover        = new Rover(new Position(1, 2), Direction.N);
            roverService = new RoverService(rover, new Plateau(5, 5, new Result()), new Result());

            var ex = Assert.Throws <Exception>(() => roverService.Process("LRAR"));

            Assert.AreEqual("Commands invalid", ex.Message);
        }
        public HttpResponseMessage MoveRover(RoverUpdateModel roverUpdateModel)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Incorrect Data,please check your parameters!"));
            }

            //Check if rover exist First
            var roverModel = _roverService.GetRover(roverUpdateModel.Id);

            if (roverModel == null)
            {
                roverModel = _roverService.CreateRover(roverUpdateModel);
            }

            _roverService.SetPosition(roverModel.CurrentX, roverModel.CurrentY);
            _roverService.Process(roverUpdateModel.MovementInstruction);
            var finalRoverPosition = _roverService.RoverCurrentPosition(roverUpdateModel.Id);

            _roverService.UpdateRover(finalRoverPosition);


            return(Request.CreateResponse(HttpStatusCode.OK, $"Updated RoverId: { finalRoverPosition.Id} ,moved to :({finalRoverPosition.CurrentX}, { finalRoverPosition.CurrentY }){ finalRoverPosition.CurrentDirection}"));
        }