-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdag_test.go
58 lines (46 loc) · 1.02 KB
/
dag_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 goflow
import (
"testing"
)
func TestDag(t *testing.T) {
d := make(dag)
d.addNode("a")
d.addNode("b")
d.addNode("c")
d.addNode("d")
d.setDownstream("a", "b")
d.setDownstream("a", "c")
d.setDownstream("b", "d")
d.setDownstream("c", "d")
if !d.validate() {
t.Errorf("Valid dag failed validation check")
}
if !equal(d.dependencies("b"), []string{"a"}) {
t.Errorf("d.dependencies() returned %s, expected %s",
d.dependencies("b"),
[]string{"a"})
}
if !equal(d.independentNodes(), []string{"a"}) {
t.Errorf("d.independentNodes() returned %s, expected %s",
d.dependencies("b"),
[]string{"a"})
}
e := make(dag)
e.addNode("a")
e.addNode("b")
e.addNode("c")
e.setDownstream("c", "a")
e.setDownstream("a", "b")
e.setDownstream("b", "a")
if e.validate() {
t.Errorf("Invalid dag passed validation check")
}
}
func TestDagWithSingleNode(t *testing.T) {
d := make(dag)
d.addNode("a")
res := d.isDownstream("a")
if res {
t.Errorf("isDownstream() returned true for an independent node")
}
}