public void FindPath_SmallMapAfterAddingAndClearingGoals_PathHasOnePointAndAllCellsAreMax() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(1, 1, 0); goalMap.AddGoal(6, 1, 0); goalMap.ClearGoals(); List <Point> obstacles = new List <Point> { new Point(1, 2), new Point(3, 2) }; List <Point> path = goalMap.FindPath(3, 4, obstacles); Assert.AreEqual(1, path.Count); Assert.AreEqual(new Point(3, 4), path[0]); string expectedGoalMapRepresentation = @"# # # # # # # # # 48 48 48 48 # 48 # # 48 # 48 48 # 48 # # 48 # 48 48 # 48 # # 48 48 48 48 48 48 # # # # # # # # #"; Assert.AreEqual(expectedGoalMapRepresentation.Replace(" ", string.Empty), goalMap.ToString().Replace(" ", string.Empty)); }
public void FindPath_SmallMapAfterAddingAndClearingGoals_ThrowsPathNotFoundException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(1, 1, 0); goalMap.AddGoal(6, 1, 0); goalMap.ClearGoals(); goalMap.FindPath(3, 4); }
public void TryFindPath_SmallMapAfterAddingAndClearingGoals_ReturnsNull() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(1, 1, 0); goalMap.AddGoal(6, 1, 0); goalMap.ClearGoals(); Path path = goalMap.TryFindPath(3, 4); Assert.AreEqual(null, path); }
public void FindPath_SmallMapAfterAddingAndClearingGoals_PathHasOnePointAndAllCellsAreMax() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy ); GoalMap goalMap = new GoalMap( map ); goalMap.AddGoal( 1, 1, 0 ); goalMap.AddGoal( 6, 1, 0 ); goalMap.ClearGoals(); List<Point> obstacles = new List<Point> { new Point( 1, 2 ), new Point( 3, 2 ) }; List<Point> path = goalMap.FindPath( 3, 4, obstacles ); Assert.AreEqual( 1, path.Count ); Assert.AreEqual( new Point( 3, 4 ), path[0] ); string expectedGoalMapRepresentation = @"# # # # # # # # # 48 48 48 48 # 48 # # 48 # 48 48 # 48 # # 48 # 48 48 # 48 # # 48 48 48 48 48 48 # # # # # # # # #"; Assert.AreEqual( expectedGoalMapRepresentation.Replace( " ", string.Empty ), goalMap.ToString().Replace( " ", string.Empty ) ); }