Esempio n. 1
0
        public void SingleSourceTest2()
        {
            var graf = new Graf<char>();

            var rVertex = new Vertex<char>('r');
            var sVertex = new Vertex<char>('s');
            var tVertex = new Vertex<char>('t');
            var xVertex = new Vertex<char>('x');
            var yVertex = new Vertex<char>('y');

            var zVertex = new Vertex<char>('z');

            rVertex.AddDirectedEdge(5, sVertex);
            rVertex.AddDirectedEdge(3, tVertex);
            sVertex.AddDirectedEdge(2, tVertex);
            sVertex.AddDirectedEdge(6, xVertex);
            tVertex.AddDirectedEdge(7, xVertex);

            tVertex.AddDirectedEdge(4, yVertex);
            tVertex.AddDirectedEdge(2, zVertex);
            xVertex.AddDirectedEdge(-1, yVertex);

            xVertex.AddDirectedEdge(-2, zVertex);
            yVertex.AddDirectedEdge(-2, zVertex);

            graf.AddVertex(rVertex);
            graf.AddVertex(sVertex);
            graf.AddVertex(tVertex);
            graf.AddVertex(xVertex);
            graf.AddVertex(yVertex);
            graf.AddVertex(zVertex);

            graf.TopologicalShortestPaths(sVertex);
            var topologicalSort = graf.GetTopologicalSort().ToList();

            Assert.NotNull(topologicalSort);
            Assert.Equal(double.PositiveInfinity, rVertex.DiscoveryTime);
            Assert.Equal(0, sVertex.DiscoveryTime);
            Assert.Equal(2, tVertex.DiscoveryTime);
            Assert.Equal(6, xVertex.DiscoveryTime);
            Assert.Equal(5, yVertex.DiscoveryTime);
            Assert.Equal(3, zVertex.DiscoveryTime);
        }