-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathtraversal_test.go
58 lines (54 loc) · 1.11 KB
/
traversal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package goraph
import (
"fmt"
"os"
"testing"
)
func TestGraph_BFS(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_00")
if err != nil {
t.Error(err)
}
rs := BFS(g, StringID("S"))
fmt.Println("BFS:", rs) // [S A B C D T E F]
if len(rs) != 8 {
t.Errorf("should be 8 vertices but %s", g)
}
}
func TestGraph_DFS(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_00")
if err != nil {
t.Error(err)
}
rs := DFS(g, StringID("S"))
fmt.Println("DFS:", rs) // [S C E B A D T F]
if len(rs) != 8 {
t.Errorf("should be 8 vertices but %s", g)
}
}
func TestGraph_DFSRecursion(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_00")
if err != nil {
t.Error(err)
}
rs := DFSRecursion(g, StringID("S"))
fmt.Println("DFSRecursion:", rs) // [S C E T A B D F]
if len(rs) != 8 {
t.Errorf("should be 8 vertices but %s", g)
}
}