Exemple #1
0
        public void TestFindPathTo()
        {
            /*
             * Тестовый город дает нам несколько дорог и, соответственно, построек.
             * Тип построек подбирается случайным образом, но так как мы задаем конкретный сид рандома
             * (в функции GenerateTestCityGraph), то первой постройкой (и соответственно вершиной в графе),
             * будет являться госпиталь.
             *
             * В первую очередь нужно убедиться в том, что выполняется условие «стартовая точка не может
             * оказаться конечной». Для этого пытаемся найти путь до точки того же типа, что и стартовая.
             */
            Graph    graph    = DataGenerator.GenerateTestCityGraph();
            PathInfo pathInfo = Finder.FindPathTo(graph, graph.Vertices.First(), InstitutionType.Hospital);

            Assert.IsFalse(pathInfo.IsEmptyPath());

            // Проверяем ситуацию, когда весь город состоит из искомых объектов.
            City  cityWithSameInstitutes  = DataGenerator.GenerateTestCity(new PostOfficeBuilder());
            Graph graphWithSameInstitutes = Finder.ConvertCityToGraph(cityWithSameInstitutes);

            pathInfo = Finder.FindPathTo(graphWithSameInstitutes,
                                         graphWithSameInstitutes.Vertices.First(), InstitutionType.PostOffice);

            Assert.IsFalse(pathInfo.IsEmptyPath());

            // Проверяем ситуацию, когда в городе нет искомого объекта.
            pathInfo = Finder.FindPathTo(graphWithSameInstitutes,
                                         graphWithSameInstitutes.Vertices.First(), InstitutionType.Hospital);

            Assert.IsTrue(pathInfo.IsEmptyPath());
        }
Exemple #2
0
        public void TestFindPathToOverload()
        {
            City city = DataGenerator.GenerateTestCity();

            // Проверка перегрузки метода поиска, который принимает город и объект учреждения, а не граф.
            // Результаты должны быть идентичны версии с графом.

            Graph    graph         = DataGenerator.GenerateTestCityGraph();
            PathInfo graphPathInfo = Finder.FindPathTo(graph, graph.Vertices.First(),
                                                       InstitutionType.Hospital);
            CityPathInfo cityPathInfo = Finder.FindPathTo(city, city.Institutions.First(),
                                                          InstitutionType.Hospital);

            Assert.AreEqual(graphPathInfo.Path.Length, cityPathInfo.Path.Length);
            Assert.AreEqual(graphPathInfo.TotalLength, cityPathInfo.TotalLength);
        }
        public void TestFindShortestPath1()
        {
            Graph             graph             = DataGenerator.GenerateTestCityGraph();
            DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm(graph);

            Vertex   startVertex = graph.Vertices[0]; // 10;0
            Vertex   endVertex   = graph.Vertices[8]; // 0;0
            PathInfo pathInfo    = dijkstraAlgorithm.FindShortestPath(startVertex, endVertex);

            Assert.AreEqual(5, pathInfo.Path.Length);
            Assert.AreEqual(10, pathInfo.TotalLength);

            startVertex = graph.Vertices[1]; // 10;10
            endVertex   = graph.Vertices[2]; // 10;11
            pathInfo    = dijkstraAlgorithm.FindShortestPath(startVertex, endVertex);
            Assert.AreEqual(2, pathInfo.Path.Length);
            Assert.AreEqual(1, pathInfo.TotalLength);
        }