25 lines
433 B
Go
25 lines
433 B
Go
package bfs
|
|
|
|
import (
|
|
"algorithms-go/DataStructure/graph"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestBfs(t *testing.T) {
|
|
h := graph.NewDirected()
|
|
|
|
for i := 0; i < 10; i++ {
|
|
h.AddVertex(graph.VertexId(i))
|
|
}
|
|
|
|
for i := 0; i < 9; i++ {
|
|
h.AddEdge(graph.VertexId(i), graph.VertexId(i+1), 1)
|
|
}
|
|
count := 0
|
|
Bfs(h, graph.VertexId(3), func(id graph.VertexId) {
|
|
count += int(id)
|
|
})
|
|
assert.Equal(t, 42, count)
|
|
}
|