예제 #1
0
        public void GraphConnectedComponents()
        {
            var g  = graph.DeepCopy();
            var cc = new ConnectedComponents(g);

            Assert.AreEqual(3, cc.AmountOfComponents);
            Assert.IsTrue(cc.Connected(0, 1));
            Assert.IsTrue(cc.Connected(7, 8));
            Assert.IsTrue(cc.Connected(9, 12));
            CollectionAssert.AreEqual(new List <int>()
            {
                7, 8
            }, cc.GetVerticesForComponent(1));
        }
예제 #2
0
        public void GraphConnectedComponentsSelfLoop()
        {
            var graph = new UndirectedGraph(1);

            graph.AddEdge(0, 0);
            var cc = new ConnectedComponents(graph);

            Assert.AreEqual(1, cc.AmountOfComponents);
            Assert.AreEqual(0, cc.ComponentId(0));
            Assert.IsTrue(cc.Connected(0, 0));
        }
예제 #3
0
        public void ConnectedComponentsWhenEveryVertexIsolatedNoVerticesConnected(int vertex1, int vertex2)
        {
            WeightedGraph <int> graph = new WeightedGraph <int>
            {
                new WeightedEdge <int>(1, 1),
                new WeightedEdge <int>(2, 2),
                new WeightedEdge <int>(3, 3)
            };

            ConnectedComponents <int> cc = new ConnectedComponents <int>(graph);

            Assert.IsFalse(cc.Connected(vertex1, vertex2));
        }
예제 #4
0
        public void ConnectedComponentsTwoVerticesConnected()
        {
            WeightedGraph <int> graph = new WeightedGraph <int>
            {
                new WeightedEdge <int>(1, 2),
                new WeightedEdge <int>(2, 3),
                new WeightedEdge <int>(3, 4)
            };

            ConnectedComponents <int> cc = new ConnectedComponents <int>(graph);

            Assert.IsTrue(cc.Connected(4, 2));
        }