Example #1
0
    def test_setting_value(self):
        tree = prefix_tree.StringPrefixTree()
        tree["abcd"] = 7
        node_chain = self._flatten_branch("abcd", tree)
        self.assertEqual(5, len(node_chain))
        for node in node_chain[1:-1]:
            self.assertEqual(node.value, None)
            self.assertEqual(node.is_set, False)
            self.assertEqual(1, node.size)

        self.assertEqual(True, node_chain[4].is_set)
        self.assertEqual(7, node_chain[4].value)
        self.assertEqual(1, node_chain[4].size)
Example #2
0
 def test_len(self):
   tree = prefix_tree.StringPrefixTree()
   tree["abcd"] = 4
   tree["ab"] = 2
   node_chain = self._flatten_branch("abcd", tree)
   self.assertEquals(5, len(node_chain))
   self.assertEquals(2, len(tree))
   for index, node in enumerate(node_chain):
     if index in [2,4]:
       self.assertEquals(True, node.is_set)
       self.assertEquals(index, node.value)
     else:
       self.assertEquals(False, node.is_set)
       self.assertEquals(None, node.value)
     self.assertEquals(2 if index <= 2 else 1, node.size)
Example #3
0
 def test_getting_value(self):
   tree = prefix_tree.StringPrefixTree()
   tree["abcd"] = 7
   self.assertEquals(7, tree["abcd"])