コード例 #1
0
    def test_longest_common_prefix(self, prefix, suffix):
        prefix_fragment = MatchFragment(prefix)
        fragment = MatchFragment(prefix + suffix)

        self.assertEqual(fragment.longest_common_prefix(prefix_fragment),
                         prefix_fragment.longest_common_prefix(fragment))

        self.assertEqual(len(prefix),
                         fragment.longest_common_prefix(prefix_fragment))
コード例 #2
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
class TestShortWildCardEdges(unittest.TestCase):
    def setUp(self):
        self.g = Graph()
        self.a = MatchFragment(b"a", bytes([1]))
        self.b = MatchFragment(b"ba", bytes([1, 1]))
        self.c = MatchFragment(b"ccc", bytes([1, 1, 1]))

    def test_longest_common_prefix(self):
        self.assertEqual(self.a.longest_common_prefix(self.b), 1)
        self.assertEqual(self.b.longest_common_prefix(self.a),
                         self.a.longest_common_prefix(self.b))
        self.assertEqual(self.c.longest_common_prefix(self.a), 1)
        self.assertEqual(self.b.longest_common_prefix(self.c), 2)

    def test_minimality(self):
        self.g.insert(self.a, "a")
        self.g.insert(self.b, "b")
        self.g.insert(self.c, "c")
        self.assertEqual(len(list(self.g.edges_at(0))), 1)