def test_traverse_with_data(self): """Verify that traversal of our Trie is depth-first and pre-order.""" tree = trie.Trie() tree.add('A', 'A') tree.add('a', 'a') tree.add('AB', 'B') tree.add('Ab', 'b') tree.add('AbC', 'C') tree.add('Abc', 'c') # The trie tree here should look something like # # <root> # / \ # A a # / | # B b # / \ # C c # # And the traversal should look like: # # A B b C c a expected_order = ['A', 'B', 'b', 'C', 'c', 'a'] for expected, actual_node in zip(expected_order, tree.traverse()): assert actual_node.prefix == expected
def test_find(self): """Exercise the Trie.find method.""" tree = trie.Trie() tree.add('A', 'A') tree.add('a', 'a') tree.add('AB', 'AB') tree.add('Ab', 'Ab') tree.add('AbC', 'AbC') tree.add('Abc', 'Abc') assert tree.find('AB').data == ['AB'] assert tree.find('AbC').data == ['AbC'] assert tree.find('A').data == ['A'] assert tree.find('X') is None
def __init__(self): """Initialize an empty notifier object.""" self.listeners = _trie.Trie()
def test_traverse_without_data(self): """Verify the behaviour when traversing an empty Trie.""" tree = trie.Trie() assert list(tree.traverse()) == []