File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ func (g *Graph) Add(v dag.Vertex) dag.Vertex {
5656func (g * Graph ) ConnectTo (source dag.Vertex , target []string ) []string {
5757 g .once .Do (g .init )
5858
59- // TODO: test
6059 var missing []string
6160 for _ , t := range target {
6261 if dest := g .dependableMap [t ]; dest != nil {
@@ -78,3 +77,12 @@ func (g *Graph) init() {
7877 g .dependableMap = make (map [string ]dag.Vertex )
7978 }
8079}
80+
81+ // GraphNodeDependable is an interface which says that a node can be
82+ // depended on (an edge can be placed between this node and another) according
83+ // to the well-known name returned by DependableName.
84+ //
85+ // DependableName can return multiple names it is known by.
86+ type GraphNodeDependable interface {
87+ DependableName () []string
88+ }
Load diff This file was deleted.
Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -18,7 +18,42 @@ func TestGraphAdd(t *testing.T) {
1818 }
1919}
2020
21+ func TestGraphConnectTo (t * testing.T ) {
22+ var g Graph
23+ g .Add (& testGraphDependable {VertexName : "a" , Mock : []string {"a" }})
24+ b := g .Add (& testGraphDependable {VertexName : "b" })
25+
26+ if missing := g .ConnectTo (b , []string {"a" }); len (missing ) > 0 {
27+ t .Fatalf ("bad: %#v" , missing )
28+ }
29+
30+ actual := strings .TrimSpace (g .String ())
31+ expected := strings .TrimSpace (testGraphConnectDepsStr )
32+ if actual != expected {
33+ t .Fatalf ("bad: %s" , actual )
34+ }
35+ }
36+
37+ type testGraphDependable struct {
38+ VertexName string
39+ Mock []string
40+ }
41+
42+ func (v * testGraphDependable ) Name () string {
43+ return v .VertexName
44+ }
45+
46+ func (v * testGraphDependable ) DependableName () []string {
47+ return v .Mock
48+ }
49+
2150const testGraphAddStr = `
225142
235284
2453`
54+
55+ const testGraphConnectDepsStr = `
56+ a
57+ b
58+ a
59+ `
You can’t perform that action at this time.
0 commit comments