예제 #1
0
        public void Find_FromVertexDisconnectedFromToVertex_EmptyPath()
        {
            var graph = AdjacencyListFactory.CreateDirected();

            graph.AddVertex("a")
            .AddEdge("b")
            .AddEdge("c")
            .AddEdge("g");
            graph.AddVertex("c")
            .AddEdge("d")
            .AddEdge("e")
            .AddEdge("f");
            graph.AddVertex("f")
            .AddEdge("g");
            //path of graph not connected with others
            graph.AddVertex("m")
            .AddEdge("n");
            graph.AddVertex("n")
            .AddEdge("o");

            var search = new DepthFirstSearch(graph);
            var result = search.BuildPath("a").GetPathString("n");

            result.Should().Be("");
        }
예제 #2
0
        public void Find_ValidInput_ShouldFindPath()
        {
            var graph = AdjacencyListFactory.CreateDirected();

            graph.AddVertex("a")
            .AddEdge("b")
            .AddEdge("c")
            .AddEdge("g");
            graph.AddVertex("c")
            .AddEdge("d")
            .AddEdge("e")
            .AddEdge("f");
            graph.AddVertex("f")
            .AddEdge("g");

            var search = new DepthFirstSearch(graph);
            var result = search.BuildPath("a").GetPathString("e");

            (result == "ace" || result == "agfce").Should().BeTrue();
        }