-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorythms_test.go
57 lines (49 loc) · 1.03 KB
/
algorythms_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
package graph
import (
"fmt"
"testing"
)
func TestBFS(t *testing.T) {
var g AbstractGraph
g.Graph = make(map[*Node]map[*Node]int, 3)
var a, b, c, d, e, f Node
a.Name = "a"
b.Name = "b"
c.Name = "c"
d.Name = "d"
e.Name = "e"
f.Name = "f"
g.Graph[&a] = make(map[*Node]int, 2)
g.Graph[&a][&b] = 1
g.Graph[&a][&c] = 1
g.Graph[&b] = make(map[*Node]int, 2)
g.Graph[&b][&d] = 1
g.Graph[&b][&e] = 1
g.Graph[&c] = make(map[*Node]int, 1)
g.Graph[&c][&f] = 1
fmt.Println(g.BFS("a", func(want interface{}) bool {
return false
}))
}
func TestDFS(t *testing.T) {
var g AbstractGraph
g.Graph = make(map[*Node]map[*Node]int, 3)
var a, b, c, d, e, f Node
a.Name = "a"
b.Name = "b"
c.Name = "c"
d.Name = "d"
e.Name = "e"
f.Name = "f"
g.Graph[&a] = make(map[*Node]int, 2)
g.Graph[&a][&b] = 1
g.Graph[&a][&c] = 1
g.Graph[&b] = make(map[*Node]int, 2)
g.Graph[&b][&d] = 1
g.Graph[&b][&e] = 1
g.Graph[&c] = make(map[*Node]int, 1)
g.Graph[&c][&f] = 1
fmt.Println(g.DFS("a", func(want interface{}) bool {
return false
}))
}