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=[])
def setUp(self): self.trie = Trie()
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()))