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

Function TestHasCycle

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

Source from the content-addressed store, hash-verified

5)
6
7func TestHasCycle(t *testing.T) {
8 graph := Graph{Directed: true}
9 edges := [][]int{{0, 1}, {1, 2}, {2, 0}, {4, 0}}
10 for _, edge := range edges {
11 graph.AddEdge(edge[0], edge[1])
12 }
13 if !graph.HasCycle() {
14 t.Error("answer of hasCycle is not correct")
15 }
16
17 graph = Graph{Directed: true}
18 edges = [][]int{{0, 1}, {1, 2}, {2, 6}, {4, 0}}
19 for _, edge := range edges {
20 graph.AddEdge(edge[0], edge[1])
21 }
22 if graph.HasCycle() {
23 t.Error("answer of hasCycle is not correct")
24 }
25}
26
27func TestFindAllCycles(t *testing.T) {
28 graph := Graph{Directed: true}

Callers

nothing calls this directly

Calls 2

AddEdgeMethod · 0.95
HasCycleMethod · 0.95

Tested by

no test coverage detected