public static RoverCount Insert(string input) { var roverCount = new RoverCount { Count = input.ConvertInt(), IsSuccess = true }; return(roverCount); }
public void MissionStart_InValid_IsSuccesMission() { var plateu = new Plateau() { X = 5, Y = 5, IsSuccess = true }; var roverCount = new RoverCount() { Count = 2, IsSuccess = true }; var roverOne = new Rover() { Info = new RoverInfo() { X = 1, Y = 2, Direction = Compass.N, IsSuccess = true }, Moves = new RoverMove() { Moves = "LMLMLMLMM", IsSuccess = true }, IsSuccess = true }; var roverTwo = new Rover() { Info = new RoverInfo() { X = 5, Y = 5, Direction = Compass.E, IsSuccess = true }, Moves = new RoverMove() { Moves = "MMRMMRMRRM", IsSuccess = true }, IsSuccess = true }; var roverList = new List <Rover> { roverOne, roverTwo }; var mission = new Mission { Plateau = plateu, RoverCount = roverCount, Rovers = roverList, IsSuccess = true }; var result = service.MissionStart(mission); Assert.IsTrue(result.Any(x => !x.IsSuccess)); }
public static List <RoverInfo> MissionStart(MarsRoverService service, Mission mission) { Console.BackgroundColor = ConsoleColor.Black; foreach (PropertyInfo propertyInfo in mission.GetType().GetProperties()) { switch (propertyInfo.Name) { case nameof(mission.Plateau): if (mission.Plateau.IsSuccess) { break; } Console.Write("Plateau Info :"); Plateau plateau = service.AddPlateu(Console.ReadLine()); mission.Plateau = plateau; break; case nameof(mission.RoverCount): if (mission.RoverCount.IsSuccess) { break; } Console.Write("Rover Count:"); RoverCount roverCount = service.AddRoverCount(Console.ReadLine()); mission.RoverCount = roverCount; var rovers = new List <Rover>(); for (int i = 0; i < roverCount.Count; i++) { rovers.Add(new Rover()); } mission.Rovers = rovers; break; case nameof(mission.Rovers): for (int i = 0; i < mission.RoverCount.Count; i++) { if (mission.Rovers[i].IsSuccess) { break; } Console.WriteLine($"{i} - Rover Setup "); RoverInfo roverInfo = service.SetupRoverInfo(Console.ReadLine()); RoverMove roverMove = service.SetupRoverMove(Console.ReadLine()); mission.Rovers[i] = service.AddRover(roverInfo, roverMove); } Console.WriteLine($" Rover Setup End "); break; default: break; } } var result = new List <RoverInfo>(); for (int i = 0; i < mission.RoverCount.Count; i++) { var rover = mission.Rovers[i]; var serviceResult = service.StartDiscovering(mission.Plateau, rover); result.Add(serviceResult); Console.WriteLine($"Info Mission > {i} - Rover : {serviceResult.X} {serviceResult.Y} {serviceResult.Direction}, IsSuccess:{serviceResult.IsSuccess} "); if (!serviceResult.IsSuccess) { Console.WriteLine($" \t Failed Detail: { serviceResult.ErrorMessage }"); } } ; return(result); }