MCPcopy
hub / github.com/arnauddri/algorithms / TestDirectedGraph

Function TestDirectedGraph

data-structures/graph/graph_test.go:104–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestDirectedGraph(t *testing.T) {
105 g := NewDirected()
106
107 for i := 0; i < 10; i++ {
108 g.AddVertex(VertexId(i))
109 }
110
111 if len(g.edges) != 10 {
112 fmt.Println(g)
113 t.Error()
114 }
115
116 for i := 0; i < 10; i++ {
117 g.AddEdge(VertexId(i), VertexId(i%2), 1)
118 }
119
120 r := g.Reverse()
121 if !r.IsEdge(1, 7) || r.IsEdge(8, 0) {
122 fmt.Println(r.edges)
123 t.Error()
124 }
125
126 successors := r.GetSuccessors(1).VerticesIter()
127 for successor := range successors {
128 if successor != 3 &&
129 successor != 5 &&
130 successor != 7 &&
131 successor != 9 {
132 t.Error()
133 }
134 }
135
136 predecessors := g.GetPredecessors(1).VerticesIter()
137 for predecessor := range predecessors {
138 if predecessor != 3 &&
139 predecessor != 5 &&
140 predecessor != 7 &&
141 predecessor != 9 {
142 t.Error()
143 }
144 }
145}

Callers

nothing calls this directly

Calls 9

NewDirectedFunction · 0.85
VertexIdTypeAlias · 0.85
AddVertexMethod · 0.80
AddEdgeMethod · 0.80
ReverseMethod · 0.80
IsEdgeMethod · 0.80
GetSuccessorsMethod · 0.80
GetPredecessorsMethod · 0.80
VerticesIterMethod · 0.65

Tested by

no test coverage detected