forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_dag_test.go
38 lines (33 loc) · 992 Bytes
/
is_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
package graph
import "testing"
/*
TestIsDAG tests solution(s) with the following signature and problem description:
Vertex struct {
Val int
Edges []*Vertex
}
func IsDAG(graph []*Vertex) bool
Given a directed graph determine if it's a DAG or not. A directed acyclic graph (DAG)
is a directed graph that has no cycles.
*/
func TestIsDAG(t *testing.T) {
tests := []struct {
graph [][]int
isDAG bool
}{
{[][]int{{2}, {1, 3}, {}}, false},
{[][]int{{2, 3}, {3}, {4}, {}}, true},
{[][]int{{2, 3}, {4, 5}, {}, {}, {}}, true},
{[][]int{{2, 3, 4}, {3}, {4}, {5}, {}}, true},
{[][]int{{2, 3, 4}, {3, 5}, {5}, {3, 5}, {}}, true},
{[][]int{{2, 3, 4}, {3, 5}, {5}, {3, 5}, {5, 3}}, false},
{readmeGraphs["Figure_1_A"], true},
{readmeGraphs["Figure_1_B"], false},
{readmeGraphs["Figure_1_C"], true},
}
for i, test := range tests {
if got := IsDAG(toGraph(test.graph)); got != test.isDAG {
t.Fatalf("Failed case #%d. Want %v got %v", i, test.isDAG, got)
}
}
}