Ejemplo n.º 1
0
    def test_common_prefix_no_recursive(self):

        cases = (
            (
                ('abc', ('45', 'xyz'), 3),
                ('abc', ('45', 'xz'), 5),
                ('abc', ('45', 'x-'), 5),
                ('abc', ),
            ),
            (
                'abc',
                'abd',
                'ag',
                'a',
            ),
            (
                (1, 2, 'abc'),
                (1, 2, 'abd'),
                (1, 2),
            ),
        )

        for args in cases:
            expected = args[-1]
            args = args[:-1]

            dd('input: ', args, 'expected: ', expected)
            rst = strutil.common_prefix(*args, recursive=False)
            dd('rst: ', rst)

            self.assertEqual(expected, rst)
Ejemplo n.º 2
0
def idc_distance(idc_a, idc_b):
    if idc_a == idc_b:
        return 0

    pre_cnt = len(strutil.common_prefix(idc_a.split('.'), idc_b.split('.')))
    return 32 / (2**pre_cnt)
Ejemplo n.º 3
0
def idc_distance(idc_a, idc_b):
    if idc_a == idc_b:
        return 0

    pre_cnt = len(strutil.common_prefix(idc_a.split('.'), idc_b.split('.')))
    return 32 / (2 ** pre_cnt)
Ejemplo n.º 4
0
    def test_common_prefix(self):
        cases = (
            (
                'abc',
                'abc',
            ),
            (
                '',
                '',
                '',
            ),
            (
                (),
                (),
                (),
                (),
            ),
            (
                'abc',
                'ab',
                'ab',
            ),
            (
                'ab',
                'abd',
                'ab',
            ),
            (
                'abc',
                'abd',
                'ab',
            ),
            (
                'abc',
                'def',
                '',
            ),
            (
                'abc',
                '',
                '',
            ),
            (
                '',
                'def',
                '',
            ),
            (
                'abc',
                'abd',
                'ag',
                'a',
            ),
            (
                'abc',
                'abd',
                'ag',
                'yz',
                '',
            ),
            (
                (
                    1,
                    2,
                ),
                (
                    1,
                    3,
                ),
                (1, ),
            ),
            (
                (
                    1,
                    2,
                ),
                (
                    2,
                    3,
                ),
                (),
            ),
            (
                (
                    1,
                    2,
                    'abc',
                ),
                (
                    1,
                    2,
                    'abd',
                ),
                (
                    1,
                    2,
                    'ab',
                ),
            ),
            (
                (
                    1,
                    2,
                    'abc',
                ),
                (
                    1,
                    2,
                    'xyz',
                ),
                (
                    1,
                    2,
                ),
            ),
            (
                (
                    1,
                    2,
                    (5, 6),
                ),
                (
                    1,
                    2,
                    (5, 7),
                ),
                (
                    1,
                    2,
                    (5, ),
                ),
            ),
            (
                (
                    'abc',
                    '45',
                ),
                ('abc', '46', 'xyz'),
                (
                    'abc',
                    '4',
                ),
            ),
            (
                ('abc', ('45', 'xyz'), 3),
                ('abc', ('45', 'xz'), 5),
                ('abc', ('45', 'x-'), 5),
                (
                    'abc',
                    ('45', 'x'),
                ),
            ),
            (
                ('abc', ('45', 'xyz'), 3),
                ('abc', ('45', 'xz'), 5),
                (
                    'abc',
                    ('x', ),
                ),
                ('abc', ),
            ),
            (
                [1, 2, 3],
                [1, 2, 4],
                [1, 2],
            ),
        )

        for args in cases:
            expected = args[-1]
            args = args[:-1]

            dd('input: ', args, 'expected: ', expected)
            rst = strutil.common_prefix(*args)
            dd('rst: ', rst)

            self.assertEqual(expected, rst)