コード例 #1
0
ファイル: PrimsTests.cs プロジェクト: Miltt/Console
        public void SearchTest()
        {
            var graph = new Graph(verticesCount: 5);

            graph.AddEdge(numV: 0, numU: 1, weight: 5);
            graph.AddEdge(numV: 0, numU: 2, weight: 3);
            graph.AddEdge(numV: 0, numU: 3, weight: 7);
            graph.AddEdge(numV: 1, numU: 2, weight: 1);
            graph.AddEdge(numV: 1, numU: 3, weight: 5);
            graph.AddEdge(numV: 1, numU: 4, weight: 1);
            graph.AddEdge(numV: 2, numU: 3, weight: 1);

            var source          = graph[0];
            var minSpanningTree = Prims.GetMinSpanningTree(graph, source);

            var treeWeight = minSpanningTree.Count > 0
                ? minSpanningTree.Sum(e => e.Weight)
                : 0;
            const int minWeight = 6;

            Assert.IsTrue(treeWeight == minWeight);
        }