You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/zh-hant/codes/go/chapter_graph/graph_bfs_test.go

30 lines
809 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// File: graph_bfs_test.go
// Created Time: 2023-02-18
// Author: Reanon (793584285@qq.com)
package chapter_graph
import (
"fmt"
"testing"
. "github.com/krahets/hello-algo/pkg"
)
func TestGraphBFS(t *testing.T) {
/* 初始化無向圖 */
vets := ValsToVets([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
edges := [][]Vertex{
{vets[0], vets[1]}, {vets[0], vets[3]}, {vets[1], vets[2]}, {vets[1], vets[4]},
{vets[2], vets[5]}, {vets[3], vets[4]}, {vets[3], vets[6]}, {vets[4], vets[5]},
{vets[4], vets[7]}, {vets[5], vets[8]}, {vets[6], vets[7]}, {vets[7], vets[8]}}
graph := newGraphAdjList(edges)
fmt.Println("初始化後,圖為:")
graph.print()
/* 廣度優先走訪 */
res := graphBFS(graph, vets[0])
fmt.Println("廣度優先走訪BFS頂點序列為:")
PrintSlice(VetsToVals(res))
}