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

Function TestBfs

algorithms/graphs/bfs/bfs_test.go:9–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestBfs(t *testing.T) {
10 h := graph.NewDirected()
11
12 for i := 0; i < 10; i++ {
13 v := graph.VertexId(i)
14 h.AddVertex(v)
15 }
16
17 for i := 0; i < 9; i++ {
18 h.AddEdge(graph.VertexId(i), graph.VertexId(i+1), 1)
19 }
20
21 bfsMap := make(map[graph.VertexId]bool)
22 checkVertices := func(v graph.VertexId) {
23 bfsMap[v] = true
24 }
25
26 Bfs(h, graph.VertexId(3), checkVertices)
27
28 for i := 3; i < len(bfsMap); i++ {
29 if _, ok := bfsMap[graph.VertexId(i)]; !ok {
30 fmt.Println(bfsMap)
31 t.Error()
32 }
33 }
34}

Callers

nothing calls this directly

Calls 3

BfsFunction · 0.85
AddVertexMethod · 0.80
AddEdgeMethod · 0.80

Tested by

no test coverage detected