Пример #1
0
    def test_octopus(self):
        # octopus algorithm test
        # test straight from git docs of A, B, and C
        # but this time use octopus to find lcas of A, B, and C simultaneously
        graph = {
            "C": ["C1"],
            "C1": ["C2"],
            "C2": ["C3"],
            "C3": ["C4"],
            "C4": ["2"],
            "B": ["B1"],
            "B1": ["B2"],
            "B2": ["B3"],
            "B3": ["1"],
            "A": ["A1"],
            "A1": ["A2"],
            "A2": ["A3"],
            "A3": ["1"],
            "1": ["2"],
            "2": [],
        }

        def lookup_parents(cid):
            return graph[cid]

        lcas = ["A"]
        others = ["B", "C"]
        for cmt in others:
            next_lcas = []
            for ca in lcas:
                res = _find_lcas(lookup_parents, cmt, [ca])
                next_lcas.extend(res)
            lcas = next_lcas[:]
        self.assertEqual(set(lcas), set(["2"]))
Пример #2
0
    def run_test(dag, inputs):
        def lookup_parents(commit_id):
            return dag[commit_id]

        c1 = inputs[0]
        c2s = inputs[1:]
        return set(_find_lcas(lookup_parents, c1, c2s))
Пример #3
0
    def test_octopus(self):
        # octopus algorithm test
        # test straight from git docs of A, B, and C
        # but this time use octopus to find lcas of A, B, and C simultaneously
        graph = {
            'C': ['C1'],
            'C1': ['C2'],
            'C2': ['C3'],
            'C3': ['C4'],
            'C4': ['2'],
            'B': ['B1'],
            'B1': ['B2'],
            'B2': ['B3'],
            'B3': ['1'],
            'A': ['A1'],
            'A1': ['A2'],
            'A2': ['A3'],
            'A3': ['1'],
            '1': ['2'],
            '2': [],
        }

        def lookup_parents(cid):
            return graph[cid]

        lcas = ['A']
        others = ['B', 'C']
        for cmt in others:
            next_lcas = []
            for ca in lcas:
                res = _find_lcas(lookup_parents, cmt, [ca])
                next_lcas.extend(res)
            lcas = next_lcas[:]
        self.assertEqual(set(lcas), set(['2']))