forked from yourheropaul/inj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_test.go
73 lines (53 loc) · 1.27 KB
/
graph_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package inj
import (
"reflect"
"testing"
)
func assertNoGraphErrors(t *testing.T, g *Graph) {
if len(g.Errors) != 0 {
t.Fatalf("Graph was initialised with errors > 0")
}
if g.UnmetDependencies != 0 {
t.Fatalf("Graph was initialised with UnmetDependencies > 0")
}
}
// New graphs should be different objects
func Test_GraphInitialisation1(t *testing.T) {
g1, g2 := NewGraph(), NewGraph()
if g1 == g2 {
t.Errorf("g1 == g2")
}
}
// Initial graph state should be zero values
func Test_GraphInitialisation2(t *testing.T) {
g := NewGraph()
if len(g.Errors) != 0 {
t.Errorf("Graph was initialised with errors > 0")
}
if g.UnmetDependencies != 0 {
t.Errorf("Graph was initialised with UnmetDependencies > 0")
}
}
// Added nodes should be in the graph object
func Test_GraphNodeAddition(t *testing.T) {
g := NewGraph()
typ := reflect.TypeOf(0)
if len(g.nodes) != 0 {
t.Errorf("Graph was initialised with nodes > 0")
}
n := g.add(typ)
if n == nil {
t.Errorf("New graph node is nil")
}
if len(g.nodes) != 1 {
t.Errorf("New graph node count != 1")
}
for typ2, node := range g.nodes {
if typ2 == typ && node != n {
t.Errorf("Expected typ to equate to node")
}
if node == n && typ2 != typ {
t.Errorf("Expected node to equate to typ")
}
}
}