def test_examples(self):
        in1 = parse_input("""
4 4
1 2
4 1
2 3
3 1
""")
        self.assertEqual(number_of_strongly_connected_components(in1), 2)

        in2= parse_input("""
5 7
2 1
3 2
3 1
4 3
4 1
5 2
5 3
""")
        self.assertEqual(number_of_strongly_connected_components(in2), 5)
Exemplo n.º 2
0
 def test_generated(self):
     for i in range(10):
         num_v, edges, num_components = gen_graph()
         print(
             "graph {:03} (num_components= {:4}, num_v = {:4}, num_e = {:7}) ... "
             .format(i, num_components, num_v, len(edges))),
         generated_input = graph_to_string(num_v, edges)
         adj = parse_input(generated_input)
         t_before = time.time()
         actual = number_of_strongly_connected_components(adj)
         duration = time.time() - t_before
         print("\tduration = {}".format(duration))
         self.assertEqual(actual, num_components)
Exemplo n.º 3
0
 def test1(self):
     result = number_of_strongly_connected_components([[1], [2], [0], [0]])
     self.assertEqual(2, result)
Exemplo n.º 4
0
 def test2(self):
     result = number_of_strongly_connected_components([[], [0], [1, 0],
                                                       [2, 0], [1, 2]])
     self.assertEqual(5, result)
Exemplo n.º 5
0
 def test4(self):
     result = number_of_strongly_connected_components([[], [], [0]])
     self.assertEqual(3, result)