Esempio n. 1
0
def test_retrive_collision():
    hashtable = Hashtable()
    hashtable.add("fried", "chicken")
    hashtable.add("fired", "the employee")
    actual = [hashtable.get("fried"), hashtable.get("fired")]
    expect = ["chicken", "the employee"]
    assert actual == expect
Esempio n. 2
0
def test_handle_collision():
    hashtable = Hashtable()
    hashtable.add('fall', 'to the ground')
    hashtable.add('fall', 'as in seasons')
    for bucket in hashtable._buckets:
        if bucket:
            actual = str(bucket)
    assert actual == "['fall', 'to the ground']->['fall', 'as in seasons']->None"
Esempio n. 3
0
def test_contains():
    hashtable = Hashtable()
    hashtable.add("Hello", "It is me")
    actual = hashtable.contains('Hello')
    expected = True
    assert actual == expected

    actual2 = hashtable.contains("Where")
    expected2 = False
    assert actual2 == expected2
Esempio n. 4
0
def tree_intersection(binary1, binary2):
    arr = []
    tree1 = binary1.pre_order()
    tree2 = binary2.pre_order()
    hash = Hashtable()
    for root in tree1:
        hash.add(str(root), str(root))
    for root in tree2:
        if hash.contains(str(root)):
            arr.append(root)
    if len(arr) == 0:
        return 'There are no intersections'
    else:
        return arr
Esempio n. 5
0
def test_add_key_value():
    hashtable = Hashtable()
    actual = hashtable.add("DOB", "1996")
    expect = ["DOB", "1996"]
    assert actual == expect
Esempio n. 6
0
def test_get_none_value():
    hashtable = Hashtable()
    hashtable.add('length', 174)
    actual = hashtable.get('wight')
    expect = None
    assert actual == expect
Esempio n. 7
0
def test_get_value():
    hashtable = Hashtable()
    hashtable.add('length', 174)
    actual = hashtable.get('length')
    expect = 174
    assert actual == expect