Пример #1
0
def test_search_match_of_suffix():
    root_node = Trie()
    root_node.insert("TESTED")

    expected = True
    output = root_node.search("TEST")
    assert output == expected
Пример #2
0
def test_search_word_longer_than_match():
    root_node = Trie()
    root_node.insert("TEST")

    expected = False
    output = root_node.search("TESTED")
    assert output == expected
Пример #3
0
def test_search_match_with_different_case():
    root_node = Trie()
    root_node.insert("dimitar")

    expected = False
    output = root_node.search("DIMITAR")
    assert output == expected
Пример #4
0
def testTrie():
    '''
    Here we test algorithms for a trie tree
    We test insert, search, and start-with functions
    Each node of the trie tree is an object of
    the TrieNode class, which has
    a. children hash that stores characters as hash keys
    b. endOfWord boolean indicator
    '''

    print('Create an empty trie')
    t = Trie()
    print('apple exists? ' + str(t.search('apple')))
    print('\"\" exists? ' + str(t.search('')))
    print('\"\" prefix exists? ' + str(t.startsWith('')))
    print('Insert apple')
    t.insert('apple')
    print('apple exists? ' + str(t.search('apple')))
    print('app exists? ' + str(t.search('app')))
    print('app prefix exists? ' + str(t.startsWith('app')))
    print('appe prefix exists? ' + str(t.startsWith('appe')))
    print('Insert app')
    t.insert('app')
    print('app exists? ' + str(t.search('app')))
    print('Insert @pple')
    t.insert('@pple')
    print('@pple exists? ' + str(t.search('@pple')))
Пример #5
0
def test_search_basic_with_multiple_words():
    root_node = Trie()
    root_node.insert('BEAR')
    root_node.insert('BELL')
    root_node.insert('BID')
    root_node.insert('BULL')
    root_node.insert('BUY')
    root_node.insert('SELL')
    root_node.insert('STOCK')
    root_node.insert('STOP')

    expected = True
    output = root_node.search('BULL')
    assert output == expected
Пример #6
0
def test_search_blank_empty_trie():
    root_node = Trie()

    expected = False
    output = root_node.search('')
    assert output == expected
Пример #7
0
def test_search_empty_trie():
    root_node = Trie()

    expected = False
    output = root_node.search("Dog")
    assert output == expected