Ejemplo n.º 1
0
def _rectangle(length, height, word_groups, tries):
    if length not in word_groups or height not in word_groups:
        return None
    if height not in tries:
        tries[height] = Trie(word_groups[height])  # expand list of words
    return _build(length, height, word_groups, tries, rectangle=[])
Ejemplo n.º 2
0
 def setUp(self):
     self.trie = Trie()
Ejemplo n.º 3
0
 def setUp(self):
     self.trie = Trie()
Ejemplo n.º 4
0
class TestTrie(unittest.TestCase):

    def setUp(self):
        self.trie = Trie()

    def test_one_insert(self):
        self.trie.insert('hello')
        self.assertTrue(self.trie.exists('hello'))
        self.assertFalse(self.trie.exists('bye'))

    def test_multi_inserts(self):
        self.trie.insert('hello')
        self.trie.insert('hello world')

        self.assertTrue(self.trie.exists('hello'))
        self.assertTrue(self.trie.exists('hello world'))
        self.assertFalse(self.trie.exists('hello trie'))
        self.assertFalse(self.trie.exists('foo bar'))

    def test_elements(self):
        insert_strs = ['foo', 'foo bar', 'bar', 'abc']

        for s in insert_strs:
            self.trie.insert(s)
        self.assertEqual(sorted(insert_strs), sorted(self.trie.elements()))
Ejemplo n.º 5
0
class TestTrie(unittest.TestCase):
    def setUp(self):
        self.trie = Trie()

    def test_one_insert(self):
        self.trie.insert('hello')
        self.assertTrue(self.trie.exists('hello'))
        self.assertFalse(self.trie.exists('bye'))

    def test_multi_inserts(self):
        self.trie.insert('hello')
        self.trie.insert('hello world')

        self.assertTrue(self.trie.exists('hello'))
        self.assertTrue(self.trie.exists('hello world'))
        self.assertFalse(self.trie.exists('hello trie'))
        self.assertFalse(self.trie.exists('foo bar'))

    def test_elements(self):
        insert_strs = ['foo', 'foo bar', 'bar', 'abc']

        for s in insert_strs:
            self.trie.insert(s)
        self.assertEqual(sorted(insert_strs), sorted(self.trie.elements()))