Пример #1
0
        public void ShortestPath_DestinationIsNull_ThrowsArgumentNullException()
        {
            string mapRepresentation = @"########
                                      #....#.#
                                      #.#..#.#
                                      #.#..#.#
                                      #......#
                                      ########";
            IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation);
            IMap map = Map.Create(mapCreationStrategy);
            DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map);
            ICell source      = map.GetCell(1, 4);
            ICell destination = null;

            Path shortestPath = dijkstraPathFinder.ShortestPath(source, destination);
        }
Пример #2
0
        public void ShortestPath_DestinationUnreachable_ThrowsPathNotFoundException()
        {
            string mapRepresentation = @"########
                                      #....#.#
                                      #.#..#.#
                                      #.#..#.#
                                      #....#.#
                                      ########";
            IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation);
            IMap map = Map.Create(mapCreationStrategy);
            DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map);
            ICell source      = map.GetCell(1, 1);
            ICell destination = map.GetCell(6, 1);

            dijkstraPathFinder.ShortestPath(source, destination);
        }
Пример #3
0
        public void ShortestPath_DestinationReachableFromSource_ExpectedPath()
        {
            string mapRepresentation = @"########
                                      #....#.#
                                      #.#..#.#
                                      #.#..#.#
                                      #......#
                                      ########";
            IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation);
            IMap map = Map.Create(mapCreationStrategy);
            DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map);
            ICell source      = map.GetCell(1, 4);
            ICell destination = map.GetCell(5, 4);

            Path shortestPath = dijkstraPathFinder.ShortestPath(source, destination);

            Assert.AreEqual(5, shortestPath.Length);
            Assert.AreEqual(source, shortestPath.Start);
            Assert.AreEqual(destination, shortestPath.End);
            Assert.AreEqual(map.GetCell(2, 4), shortestPath.StepForward());
        }