public void Should_have_error_Rover_Outside_Map_Border_UpperRight() { RoverMapValidator roverMapValidator = new RoverMapValidator(upperRightPointModel); IRoverModel roverModel = new RectangleRoverModel(); roverModel.X = upperRightPointModel.X; roverModel.Y = upperRightPointModel.Y; var validator = roverMapValidator.Validate(roverModel); Assert.AreEqual(true, validator.IsValid, validator.Errors.FirstOrDefault()?.ErrorMessage); }
public IRoverCommandResult Move(IRoverCommandItemModel rover, MoveType moveItem) { IRoverCommandResult roverCommandResult = new RoverCommandResult { VerboseType = ResultType.Success, Verbose = $"The movement of the rover([{rover.RoverModel.ToString()}]) for [{moveItem.ToString()}]." }; var newRoverModel = rover.RoverModel.Clone(); switch (moveItem) { case MoveType.L: newRoverModel.Direction = newRoverModel.Direction.PreviousValue(); break; case MoveType.R: newRoverModel.Direction = newRoverModel.Direction.NextValue(); break; case MoveType.M: switch (newRoverModel.Direction) { case DirectionType.E: newRoverModel.X++; break; case DirectionType.W: newRoverModel.X--; break; case DirectionType.N: newRoverModel.Y++; break; case DirectionType.S: newRoverModel.Y--; break; default: roverCommandResult.VerboseType = ResultType.Error; roverCommandResult.Verbose = (new NotImplementedException()).Message; return(roverCommandResult); } break; default: roverCommandResult.VerboseType = ResultType.Error; roverCommandResult.Verbose = (new NotImplementedException()).Message; return(roverCommandResult); } RoverMapValidator roverMapValidator = new RoverMapValidator(RoverCommandItemListModel.UpperRight); var result = roverMapValidator.Validate(newRoverModel); if (result.IsValid) { rover.RoverModel = newRoverModel; roverCommandResult.Verbose += $" -> [{newRoverModel.ToString()}]"; } else { roverCommandResult.VerboseType = ResultType.Warn; roverCommandResult.Verbose = string.Join(" ", result.Errors.Select(p => p.ErrorMessage)); } return(roverCommandResult); }