def test_search(self): trie = CCNxTrie() value = "foo" trie.insert("abcd", value) test = trie.search("abcd") self.assertTrue(test == value)
def test_insert(self): trie = CCNxTrie() token_string = "abcd" value = "foo" trie.insert(token_string, value) truth = "[ (key : a) (value : None) (left : None) (middle : [ (key : b) (value : None) (left : None) (middle : [ (key : c) (value : None) (left : None) (middle : [ (key : d) (value : foo) (left : None) (middle : None) (right : None) ]) (right : None) ]) (right : None) ]) (right : None) ]" test = str(trie.root).replace('\n', '') self.assertTrue(truth == test)
def test_search_too_long(self): trie = CCNxTrie() trie.insert("abcd", "foo") token_string = "abcde" walker = CCNxTrieWalker(trie) test_value = None success = True for i in range(0, len(token_string)): token = token_string[i] result = walker.next(token) if result == CCNxTrieWalker.NoMatch: success = False break self.assertFalse(success) self.assertTrue(walker.value() is None)
def test_search_right(self): trie = CCNxTrie() trie.insert("abcd", "foo") trie.insert("abe", "egg") test = trie.search("abe") self.assertTrue(test == "egg")
def test_search_left(self): trie = CCNxTrie() trie.insert("abcd", "foo") trie.insert("aba", "apple") test = trie.search("aba") self.assertTrue(test == "apple")
def test_search(self): trie = CCNxTrie() token_string = "abcd" value = "foo" trie.insert(token_string, value) walker = CCNxTrieWalker(trie) test_value = None success = True for i in range(0, len(token_string)): token = token_string[i] result = walker.next(token) if result == CCNxTrieWalker.NoMatch: success = False break self.assertTrue(success) self.assertTrue(walker.value() == value)
def test_insert_left(self): trie = CCNxTrie() trie.insert("abcd", "foo") trie.insert("abb", "bar") truth = "[ (key : a) (value : None) (left : None) (middle : [ (key : b) (value : None) (left : None) (middle : [ (key : c) (value : None) (left : [ (key : b) (value : bar) (left : None) (middle : None) (right : None) ]) (middle : [ (key : d) (value : foo) (left : None) (middle : None) (right : None) ]) (right : None) ]) (right : None) ]) (right : None) ]" test = str(trie.root).replace('\n', '') self.assertTrue(truth == test)
def test_search_too_long(self): trie = CCNxTrie() trie.insert("abcd", "foo") test = trie.search("abcde") self.assertTrue(test == None)