Esempio n. 1
0
 def test_two_components(self):
     adj_matrix = [
         '5\n', '0 1 1 0 0', '1 0 1 0 0', '1 1 0 0 0', '0 0 0 0 1',
         '0 0 0 1 0'
     ]
     graph = Graph.get_from_adjective_matrix(adj_matrix)
     components = graph.find_component()
     self.assertEqual({1: {0, 1, 2}, 2: {3, 4}}, components)
Esempio n. 2
0
 def test_one_component(self):
     adj_matrix = ['4\n', '0 1 1 0', '1 0 1 0', '1 1 0 1', '0 0 1 0']
     graph = Graph.get_from_adjective_matrix(adj_matrix)
     components = graph.find_component()
     self.assertEqual({1: {0, 1, 2, 3}}, components)
Esempio n. 3
0
 def test_loop(self):
     adj_matrix = ['3\n', '1 0 0', '0 1 0', '0 0 1']
     graph = Graph.get_from_adjective_matrix(adj_matrix)
     components = graph.find_component()
     self.assertEqual({1: {0}, 2: {1}, 3: {2}}, components)
Esempio n. 4
0
 def test_two_alone_vertexes(self):
     adj_matrix = ['4\n', '0 0 0 0', '0 0 1 0', '0 1 0 0', '0 0 0 0']
     graph = Graph.get_from_adjective_matrix(adj_matrix)
     components = graph.find_component()
     self.assertEqual({1: {0}, 2: {1, 2}, 3: {3}}, components)