def test_1(self): graph = undirected_graph.Graph() graph.add_edge( edge = undirected_graph.Edge( vertex1 = 1, vertex2 = 1 ) ) self.assertEqual( list( undirected_graph.connected_components( graph = graph ) ), [ [ 1 ] ], )
def test_1(self): graph = undirected_graph.Graph() graph.add_edge(edge=undirected_graph.Edge(vertex1=1, vertex2=1)) self.assertEqual( list(undirected_graph.connected_components(graph=graph)), [[1]], )
def test_2(self): graph = undirected_graph.Graph() graph.add_edge( edge = undirected_graph.Edge( vertex1 = 1, vertex2 = 2 ) ) self.assertEqual( list( sorted( c ) for c in undirected_graph.connected_components( graph = graph ) ), [ [ 1, 2 ] ], ) graph = undirected_graph.Graph() graph.add_vertex( 1 ) graph.add_vertex( 2 ) self.assertEqual( sorted( undirected_graph.connected_components( graph = graph ) ), [ [ 1 ], [ 2 ] ], )
def test_2(self): graph = undirected_graph.Graph() graph.add_edge(edge=undirected_graph.Edge(vertex1=1, vertex2=2)) self.assertEqual( list( sorted(c) for c in undirected_graph.connected_components(graph=graph)), [[1, 2]], ) graph = undirected_graph.Graph() graph.add_vertex(1) graph.add_vertex(2) self.assertEqual( sorted(undirected_graph.connected_components(graph=graph)), [[1], [2]], )
def test_3(self): graph = undirected_graph.Graph() graph.add_edge( undirected_graph.Edge( vertex1 = 1, vertex2 = 2 ) ) graph.add_edge( undirected_graph.Edge( vertex1 = 2, vertex2 = 3 ) ) graph.add_edge( undirected_graph.Edge( vertex1 = 4, vertex2 = 5 ) ) graph.add_edge( undirected_graph.Edge( vertex1 = 5, vertex2 = 6 ) ) graph.add_edge( undirected_graph.Edge( vertex1 = 5, vertex2 = 7 ) ) graph.add_edge( undirected_graph.Edge( vertex1 = 6, vertex2 = 7 ) ) self.assertEqual( sorted( sorted( c ) for c in undirected_graph.connected_components( graph = graph ) ), [ [ 1, 2, 3 ], [ 4, 5, 6, 7 ] ], )
def test_3(self): graph = undirected_graph.Graph() graph.add_edge(undirected_graph.Edge(vertex1=1, vertex2=2)) graph.add_edge(undirected_graph.Edge(vertex1=2, vertex2=3)) graph.add_edge(undirected_graph.Edge(vertex1=4, vertex2=5)) graph.add_edge(undirected_graph.Edge(vertex1=5, vertex2=6)) graph.add_edge(undirected_graph.Edge(vertex1=5, vertex2=7)) graph.add_edge(undirected_graph.Edge(vertex1=6, vertex2=7)) self.assertEqual( sorted( sorted(c) for c in undirected_graph.connected_components(graph=graph)), [[1, 2, 3], [4, 5, 6, 7]], )