def test_generate_abbreviations(self):
        word1 = "word"
        answer1 = [
            "word",
            "wor1",
            "wo1d",
            "wo2",
            "w1rd",
            "w1r1",
            "w2d",
            "w3",
            "1ord",
            "1or1",
            "1o1d",
            "1o2",
            "2rd",
            "2r1",
            "3d",
            "4",
        ]
        self.assertEqual(sorted(generate_abbreviations(word1)), sorted(answer1))

        word2 = "hello"
        answer2 = [
            "hello",
            "hell1",
            "hel1o",
            "hel2",
            "he1lo",
            "he1l1",
            "he2o",
            "he3",
            "h1llo",
            "h1ll1",
            "h1l1o",
            "h1l2",
            "h2lo",
            "h2l1",
            "h3o",
            "h4",
            "1ello",
            "1ell1",
            "1el1o",
            "1el2",
            "1e1lo",
            "1e1l1",
            "1e2o",
            "1e3",
            "2llo",
            "2ll1",
            "2l1o",
            "2l2",
            "3lo",
            "3l1",
            "4o",
            "5",
        ]
        self.assertEqual(sorted(generate_abbreviations(word2)), sorted(answer2))
Ejemplo n.º 2
0
    def test_generate_abbreviations(self):
        word1 = "word"
        answer1 = ['word', 'wor1', 'wo1d', 'wo2', 'w1rd', 'w1r1', 'w2d', 'w3',
            '1ord', '1or1', '1o1d', '1o2', '2rd', '2r1', '3d', '4']
        self.assertEqual(sorted(generate_abbreviations(word1)), sorted(answer1))

        word2 = "hello"
        answer2 = ['hello', 'hell1', 'hel1o', 'hel2', 'he1lo', 'he1l1', 'he2o',
            'he3', 'h1llo', 'h1ll1', 'h1l1o', 'h1l2', 'h2lo', 'h2l1', 'h3o', 'h4',
            '1ello', '1ell1', '1el1o', '1el2', '1e1lo', '1e1l1', '1e2o', '1e3',
            '2llo', '2ll1', '2l1o', '2l2', '3lo', '3l1', '4o', '5']
        self.assertEqual(sorted(generate_abbreviations(word2)), sorted(answer2))
Ejemplo n.º 3
0
    def test_generate_abbreviations(self):
        word1 = "word"
        answer1 = ['word', 'wor1', 'wo1d', 'wo2', 'w1rd', 'w1r1', 'w2d', 'w3',
            '1ord', '1or1', '1o1d', '1o2', '2rd', '2r1', '3d', '4']
        self.assertEqual(sorted(generate_abbreviations(word1)), sorted(answer1))

        word2 = "hello"
        answer2 = ['hello', 'hell1', 'hel1o', 'hel2', 'he1lo', 'he1l1', 'he2o',
            'he3', 'h1llo', 'h1ll1', 'h1l1o', 'h1l2', 'h2lo', 'h2l1', 'h3o', 'h4',
            '1ello', '1ell1', '1el1o', '1el2', '1e1lo', '1e1l1', '1e2o', '1e3',
            '2llo', '2ll1', '2l1o', '2l2', '3lo', '3l1', '4o', '5']
        self.assertEqual(sorted(generate_abbreviations(word2)), sorted(answer2))
Ejemplo n.º 4
0
"""
given input word, return the list of abbreviations.
ex)
word => [1ord, w1rd, wo1d, w2d, 3d, w3 ... etc]
"""
from algorithms.backtrack import generate_abbreviations

word=['word', 'wor1', 'wo1d', 'wo2', 'w1rd', 'w1r1', 'w2d', 'w3', '1ord', '1or1', '1o1d', '1o2', '2rd', '2r1', '3d', '4']
word2=['word', 'wor1', 'wo1d' ]
print(generate_abbreviations(word))

print(generate_abbreviations(word2))