-
Notifications
You must be signed in to change notification settings - Fork 77
/
topological_sort_test.go
78 lines (72 loc) · 1.72 KB
/
topological_sort_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
74
75
76
77
78
package goraph
import (
"fmt"
"os"
"testing"
"github.com/gyuho/goraph/testgraph"
)
func TestGraph_TopologicalSort_05(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_05")
if err != nil {
t.Error(err)
}
L, isDAG := TopologicalSort(g)
if isDAG != true {
t.Errorf("there is no directed cycle in the graph so isDAG should be true but %+v %+v", L, isDAG)
}
fmt.Println("graph_05:", L)
}
func TestGraph_TopologicalSort_06(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_06")
if err != nil {
t.Error(err)
}
L, isDAG := TopologicalSort(g)
if isDAG != true {
t.Errorf("there is no directed cycle in the graph so isDAG should be true but %+v %+v", L, isDAG)
}
fmt.Println("graph_06:", L)
}
func TestGraph_TopologicalSort_07(t *testing.T) {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, "graph_07")
if err != nil {
t.Error(err)
}
L, isDAG := TopologicalSort(g)
if isDAG != false {
t.Errorf("there is a directed cycle in the graph so isDAG should be false but %+v %+v", L, isDAG)
}
fmt.Println("graph_07:", L)
}
func TestGraph_TopologicalSort(t *testing.T) {
for _, graph := range testgraph.GraphSlice {
f, err := os.Open("testdata/graph.json")
if err != nil {
t.Error(err)
}
defer f.Close()
g, err := NewGraphFromJSON(f, graph.Name)
if err != nil {
t.Error(err)
}
L, isDAG := TopologicalSort(g)
if isDAG != graph.IsDAG {
t.Errorf("%s | IsDag are supposed to be %v but %+v %+v", graph.Name, graph.IsDAG, L, isDAG)
}
}
}