예제 #1
0
    def test_should_find_simple_scc(self):
        graph_with_cycle = {'foo': ['bar'],
                            'bar': ['foo']}

        strongly_connected_components = tarjan_scc(graph_with_cycle)

        self.assertEqual(strongly_connected_components, [('bar', 'foo')])
예제 #2
0
    def test_should_only_find_single_item_components_when_there_are_no_cycles(self):
        graph_with_no_cycles = {'foo': ['bar'],
                                'a': ['b'],
                                'baz': ['bar'],
                                'hello': ['foo']}

        strongly_connected_components = tarjan_scc(graph_with_no_cycles)
        self.assertEqual(strongly_connected_components, [
                         ('b',), ('a',), ('bar',), ('foo',), ('baz',), ('hello',)])
예제 #3
0
    def test_should_find_multi_item_components_when_there_are_cycles(self):
        graph_with_cycle = {'foo': ['bar'],
                            'bar': ['baz'],
                            'baz': ['abc'],
                            'abc': ['foo'],
                            'f': ['g'],
                            'j': ['k']}

        strongly_connected_components = tarjan_scc(graph_with_cycle)
        self.assertEqual(strongly_connected_components, [
                         ('baz', 'bar', 'foo', 'abc'), ('g',), ('f',), ('k',), ('j',)])
예제 #4
0
    def test_should_not_find_any_scc_when_graph_empty(self):
        empty_graph = {}

        strongly_connected_components = tarjan_scc(empty_graph)
        self.assertEqual(strongly_connected_components, [])