public DiscoveryPlan DeserializeDiscoveryPlan(string input) { if (string.IsNullOrWhiteSpace(input)) { throw new ArgumentException(); } List <string> inputLineList = new List <string>(input.Trim().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)); if (!(inputLineList.Count >= InpuMinNumber && ((inputLineList.Count - InputForPlateau) % InputNavigationPlan == 0))) { throw new ArgumentException("invalid.count"); } Plateau plateau = DeserializePlateauInput(inputLineList); List <NavigationPlan> roverNavigationPlanList = DeserializeRoverNavigationPlanList(inputLineList); DiscoveryPlan discoveryPlan = new DiscoveryPlan(); discoveryPlan.Plateau = plateau; discoveryPlan.NavigationPlanList = roverNavigationPlanList; return(discoveryPlan); }
public void DiscoveryPlanDeserializer_PositionLineException() { string testInput = "5 5\n" + "1 2 X\n" + "LMLMLMLMM\n" + "3 3 E\n" + "MMRMMRMRRM\n"; Assert.Throws <Exception>(() => { DiscoveryPlan discoveryPlan = _deserializerHelper.DeserializeDiscoveryPlan(testInput); }); }
public string ExecuteDiscoveryPlan(string input) { if (_deserializerHelper == null) { throw new ArgumentNullException("discoveryPlanDeserializer"); } DiscoveryPlan discoveryPlan = _deserializerHelper.DeserializeDiscoveryPlan(input); FinalStatus finalStatus = this.ExecuteDiscoveryPlan(discoveryPlan); string output = _deserializerHelper.SerializeFinal(finalStatus); return(output); }
public FinalStatus ExecuteDiscoveryPlan(DiscoveryPlan discoveryPlan) { List <IRoverController> roverControllerList = new List <IRoverController>(); foreach (NavigationPlan roverNavigationPlan in discoveryPlan.NavigationPlanList) { IRoverController roverController = new RoverController(); roverControllerList.Add(roverController); roverController.NavigationPlan(discoveryPlan.Plateau, roverNavigationPlan); } FinalStatus finalStatus = new FinalStatus { FinalRoverPositionList = roverControllerList.Select(roverController => roverController.Position).ToList() }; return(finalStatus); }
public void MarsRoverService_ValidDiscoveryPlanInput() { DiscoveryPlan discoveryPlan = new DiscoveryPlan { Plateau = new Plateau { LowerLefttCoordinate = new Coordinate { X = 0, Y = 0 }, UpperRightCoordinate = new Coordinate { X = 5, Y = 5 } }, NavigationPlanList = new List <NavigationPlan> { new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 1, Y = 2 }, WayType = WayType.North }, RuleTypeList = new List <RuleType> { RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Move, } }, new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 3, Y = 3 }, WayType = WayType.East }, RuleTypeList = new List <RuleType> { RuleType.Move, RuleType.Move, RuleType.Right, RuleType.Move, RuleType.Move, RuleType.Right, RuleType.Move, RuleType.Right, RuleType.Right, RuleType.Move, } } } }; FinalStatus expectedFinalStatus = new FinalStatus { FinalRoverPositionList = new List <Position> { new Position { Coordinate = new Coordinate { X = 1, Y = 3 }, WayType = WayType.North }, new Position { Coordinate = new Coordinate { X = 5, Y = 1 }, WayType = WayType.East } } }; IMarsRoverService marsRoverService = new MarsRoverService(); FinalStatus actualFinalStatus = marsRoverService.ExecuteDiscoveryPlan(discoveryPlan); Assert.Equal(expectedFinalStatus, actualFinalStatus); }