-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
57 lines (48 loc) · 1.09 KB
/
main_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 bfstree_test
import (
"testing"
"github.com/bcicen/bfstree"
)
var tree *bfstree.BFSTree
type TestEdge struct {
from string
to string
}
// TestEdge implements bfstree.Edge interface
func (t TestEdge) To() string { return t.to }
func (t TestEdge) From() string { return t.from }
func TestCreateTree(t *testing.T) {
tree = bfstree.New(
TestEdge{"a", "b"},
TestEdge{"b", "d"},
TestEdge{"d", "e"},
TestEdge{"e", "f"},
TestEdge{"f", "g"},
TestEdge{"c", "d"},
TestEdge{"c", "a"},
TestEdge{"a", "c"},
TestEdge{"b", "c"},
)
t.Logf("created tree with %d edges, %d nodes", tree.Len(), len(tree.Nodes()))
}
func TestFindLongPath(t *testing.T) {
path, err := tree.FindPath("a", "g")
if err != nil {
t.Error(err)
}
t.Logf("found path: %s", path)
}
func TestFindShortPath(t *testing.T) {
path, err := tree.FindPath("a", "b")
if err != nil {
t.Error(err)
}
t.Logf("found path: %s", path)
}
func TestFindNoPath(t *testing.T) {
_, err := tree.FindPath("a", "z")
if err == nil {
t.Errorf("no error returned on missing path")
}
t.Logf("got expected error: %s", err)
}