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

Function TestUndirectedGraph

graph/graph_test.go:104–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestUndirectedGraph(t *testing.T) {
105
106 for _, test := range graphTestCases {
107 t.Run(fmt.Sprint(test.name), func(t *testing.T) {
108 // Initializing graph, adding edges
109 graph := New(test.vertices)
110 for _, edge := range test.edges {
111 graph.AddWeightedEdge(edge[0], edge[1], edge[2])
112 }
113
114 if graph.vertices != test.vertices {
115 t.Errorf("Number of vertices, Expected: %d, Computed: %d", test.vertices, graph.vertices)
116 }
117 edgeCount := 0
118 for _, e := range graph.edges {
119 edgeCount += len(e)
120 }
121 if edgeCount != len(test.edges)*2 {
122 t.Errorf("Number of edges, Expected: %d, Computed: %d", len(test.edges)*2, edgeCount)
123 }
124 for _, edge := range test.edges {
125 if val, found := graph.edges[edge[0]][edge[1]]; !found || val != edge[2] {
126 t.Errorf("Edge {%d->%d (%d)} not found", edge[0], edge[1], edge[2])
127 }
128 }
129 })
130 }
131}

Callers

nothing calls this directly

Calls 2

AddWeightedEdgeMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected