MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / test_contains_edge

Method test_contains_edge

graphs/graph_adjacency_matrix.py:412–444  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

410 )
411
412 def test_contains_edge(self) -> None:
413 # generate graphs and graph input
414 vertex_count = 20
415 (
416 undirected_graph,
417 directed_graph,
418 random_vertices,
419 random_edges,
420 ) = self.__generate_graphs(vertex_count, 0, 100, 4)
421
422 # generate all possible edges for testing
423 all_possible_edges: list[list[int]] = []
424 for i in range(vertex_count - 1):
425 for j in range(i + 1, vertex_count):
426 all_possible_edges.append([random_vertices[i], random_vertices[j]])
427 all_possible_edges.append([random_vertices[j], random_vertices[i]])
428
429 # test contains_edge function
430 for edge in all_possible_edges:
431 if edge in random_edges:
432 self.__assert_graph_edge_exists_check(
433 undirected_graph, directed_graph, edge
434 )
435 elif [edge[1], edge[0]] in random_edges:
436 # since this edge exists for undirected but the reverse may
437 # not exist for directed
438 self.__assert_graph_edge_exists_check(
439 undirected_graph, directed_graph, [edge[1], edge[0]]
440 )
441 else:
442 self.__assert_graph_edge_does_not_exist_check(
443 undirected_graph, directed_graph, edge
444 )
445
446 def test_add_edge(self) -> None:
447 # generate graph input

Callers

nothing calls this directly

Tested by

no test coverage detected