github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/algorithm/datastructures/topology/topo_test.go (about)

     1  package topology
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func buildGraph() *Graph {
     8  	g := NewGraph()
     9  	g.AddVertex(1, "A")
    10  	g.AddVertex(2, "B")
    11  	g.AddVertex(3, "C")
    12  	g.AddVertex(4, "D")
    13  	//g.AddVertex(5, "E")
    14  	g.AddEdge(1, 2)
    15  	g.AddEdge(2, 3)
    16  	g.AddEdge(4, 2)
    17  	//g.AddEdge(3, 1)
    18  	return g
    19  }
    20  
    21  func Test_topoSortKahn(t *testing.T) {
    22  	g := buildGraph()
    23  	topSort := topoSortKahn(g)
    24  	t.Log(topSort)
    25  }
    26  
    27  func Test_topoSortDFS(t *testing.T) {
    28  	g := buildGraph()
    29  	topoSortDFS(g)
    30  }