MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestFindAllCycles

Function TestFindAllCycles

graph/cycle_test.go:27–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25}
26
27func TestFindAllCycles(t *testing.T) {
28 graph := Graph{Directed: true}
29 edges := [][]int{{0, 4}, {1, 3}, {2, 3}, {3, 4}, {4, 7}, {5, 2}, {6, 3}, {7, 3}}
30 for _, edge := range edges {
31 graph.AddEdge(edge[0], edge[1])
32 }
33
34 res := graph.FindAllCycles()
35
36 if len(res) != 1 {
37 t.Error("number of cycles is not correct")
38 }
39
40 firstCycle := res[0]
41 if len(firstCycle.edges) != 3 {
42 t.Error("number of vertex in cycle is not correct")
43 }
44 if _, ok := firstCycle.edges[3][4]; !ok {
45 t.Error("connection in cycle is not correct")
46 }
47 if _, ok := firstCycle.edges[4][7]; !ok {
48 t.Error("connection in cycle is not correct")
49 }
50 if _, ok := firstCycle.edges[7][3]; !ok {
51 t.Error("connection in cycle is not correct")
52 }
53}

Callers

nothing calls this directly

Calls 2

AddEdgeMethod · 0.95
FindAllCyclesMethod · 0.95

Tested by

no test coverage detected