MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestTopological

Function TestTopological

graph/topological_test.go:36–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34}
35
36func TestTopological(t *testing.T) {
37 for _, tc := range testCases {
38 t.Run(tc.name, func(t *testing.T) {
39 actual := Topological(tc.N, tc.constraints)
40
41 visited := make([]bool, tc.N)
42 positions := make([]int, tc.N)
43 for i := 0; i < tc.N; i++ {
44 positions[actual[i]] = i
45 visited[actual[i]] = true
46 }
47 for _, v := range visited {
48 if !v {
49 t.Errorf("nodes not all visited, %v", visited)
50 }
51 }
52 for _, c := range tc.constraints {
53 if positions[c[0]] > positions[c[1]] {
54 t.Errorf("%v dun satisfy %v", actual, c)
55 }
56 }
57 })
58 }
59}

Callers

nothing calls this directly

Calls 1

TopologicalFunction · 0.85

Tested by

no test coverage detected