예제 #1
0
        public void FindDisconnectedSubGraphsTest()
        {
            SimpleGraph <string, Edge <string> > graph = new SimpleGraph <string, Edge <string> >(false);

            graph.Add(new Edge <string>("A", "B", false));              // A->B
            graph.Add(new Edge <string>("A", "C", false));              // A->C
            graph.Add(new Edge <string>("B", "D", false));              // B->D
            graph.Add(new Edge <string>("C", "D", false));              // C->D
            graph.Add(new Edge <string>("D", "E", false));              // D->E
            graph.Add(new Edge <string>("G", "F", false));              // G->F, different subgraph

            Assert.IsFalse(graph.IsConnected());

            DisconnectedGraphsFinder <string, Edge <string> > finder = new DisconnectedGraphsFinder <string, Edge <string> >(
                () => new SubGraphView <string, Edge <string> >(graph), graph);

            finder.FindDisconnectedGraphs();
            Assert.AreEqual(2, finder.FoundDisconnectedGraphs.Count);
            Assert.AreEqual(5, finder.FoundDisconnectedGraphs[0].Vertices.Count());
            Assert.AreEqual(2, finder.FoundDisconnectedGraphs[1].Vertices.Count());
            Assert.AreEqual(5, finder.FoundDisconnectedGraphs[0].Edges.Count());
            Assert.AreEqual(1, finder.FoundDisconnectedGraphs[1].Edges.Count());

            finder.FindDisconnectedGraphs("A", true);
            Assert.AreEqual(1, finder.FoundDisconnectedGraphs.Count);
            Assert.AreEqual(5, finder.FoundDisconnectedGraphs[0].Vertices.Count());
            Assert.AreEqual(5, finder.FoundDisconnectedGraphs[0].Edges.Count());
        }
예제 #2
0
        public void IsConnectedTestUsingSimpleNonDirectedGraph()
        {
            SimpleGraph <string, Edge <string> > graph = new SimpleGraph <string, Edge <string> >(false);

            graph.Add(new Edge <string>("A", "B", false));              // A->B
            graph.Add(new Edge <string>("A", "C", false));              // A->C
            graph.Add(new Edge <string>("B", "D", false));              // B->D
            graph.Add(new Edge <string>("C", "D", false));              // C->D
            graph.Add(new Edge <string>("D", "E", false));              // D->E

            Assert.IsTrue(graph.IsConnected());

            // Add an un-connected edge.
            Edge <string> toAdd = new Edge <string>("G", "F", false);

            graph.Add(toAdd);

            Assert.IsFalse(graph.IsConnected());

            // Add a directed edge from F to A.
            toAdd = new Edge <string>("F", "A", false);
            graph.Add(toAdd);

            Assert.IsTrue(graph.IsConnected());
        }