def test_not_contains():
    hashtable = Hashtable()
    hashtable.set('one', '1')

    actual = hashtable.contains('two')
    expect = False

    assert actual == expect
def test_contains():
    hashtable = Hashtable()
    hashtable.set('one', '1')

    actual = hashtable.contains('one')
    expect = True

    assert actual == expect
示例#3
0
def tree_intersection(tree1, tree2) -> list:
    common_vals = []
    if tree1.root and tree2.root:
        tree1_list, tree2_list = tree1.pre_order(), tree2.pre_order()
        hashy = Hashtable()
        for val in tree1_list: hashy.add(str(val), "number")
        for val in tree2_list: 
            if hashy.contains(str(val)): common_vals.append(int(val))
    return common_vals
def comb(string):
    words = string.replace(",", "").replace(".", "").split(" ")
    ht = Hashtable()
    for word in words:
        word = word.lower()
        if ht.contains(word):
            return word
        else:
            ht.add(key=word, value=word)
def repeat_word(text: str) -> str:
    valid_chars = "abcdefghijklmnopqrstuvwxyz "
    words = "".join([x for x in text.lower() if x in valid_chars])
    hashy = Hashtable()
    for word in words.split():
        if hashy.contains(word):
            return word
        hashy.add(word, "word")

    return "no duplicate words found"
示例#6
0
def word_repeat(string):
    words = string.replace(',', '').replace('.', '').split(" ")
    ht = Hashtable()

    for word in words:
        word = word.lower()
        if ht.contains(word):
            return word
        else:
            ht.add(word, word)
def tree_intersection(bt1, bt2):
    new_arr = []
    tree1 = bt1.pre_order()
    tree2 = bt2.pre_order()
    ht = Hashtable()
    for value in tree1:
        ht.add(key=str(value), value=value)
    for value in tree2:
        if ht.contains(str(value)):
            new_arr.append(value)
    return new_arr
def test_key_that_does_not_exist():
    hashtable = Hashtable()
    hashtable.add('Sunday', 'One')
    actual = hashtable.contains('Monday')
    expected = False
    assert actual == expected
def test_adding_keyval_pair():
    hashtable = Hashtable()
    hashtable.add('Sunday', 'One')
    actual = hashtable.contains('Sunday')
    expected = True
    assert actual == expected
示例#10
0
def test_contains():
    ht = Hashtable()
    ht.add('rum ham', 6)
    actual = ht.contains('toe knife')
    expected = False
    assert actual == expected