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)
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)
def test1(self): result = number_of_strongly_connected_components([[1], [2], [0], [0]]) self.assertEqual(2, result)
def test2(self): result = number_of_strongly_connected_components([[], [0], [1, 0], [2, 0], [1, 2]]) self.assertEqual(5, result)
def test4(self): result = number_of_strongly_connected_components([[], [], [0]]) self.assertEqual(3, result)