Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 def __init__(self):
     """Initialize an empty notifier object."""
     self.listeners = _trie.Trie()
Exemplo n.º 4
0
 def test_traverse_without_data(self):
     """Verify the behaviour when traversing an empty Trie."""
     tree = trie.Trie()
     assert list(tree.traverse()) == []