def test_left_join_empty_hashmap():
    ht1 = HashTable()
    ht2 = HashTable()
    assert left_join(ht1, ht2) == []
Beispiel #2
0
if __name__ == "__main__":
    tree1 = BinaryTree()
    tree1.root = TNode(150)
    tree1.root.left = TNode(100)
    tree1.root.right = TNode(250)
    tree1.root.left.left = TNode(75)
    tree1.root.left.right = TNode(160)
    tree1.root.left.right.left = TNode(125)
    tree1.root.left.right.right = TNode(175)
    tree1.root.right.left = TNode(200)
    tree1.root.right.right = TNode(350)
    tree1.root.right.right.left = TNode(300)
    tree1.root.right.right.right = TNode(500)

    tree2 = BinaryTree()
    tree2.root = TNode(42)
    tree2.root.left = TNode(100)
    tree2.root.right = TNode(600)
    tree2.root.left.left = TNode(15)
    tree2.root.left.right = TNode(160)
    tree2.root.left.right.left = TNode(125)
    tree2.root.left.right.right = TNode(175)
    tree2.root.right.left = TNode(200)
    tree2.root.right.right = TNode(350)
    tree2.root.right.right.left = TNode(4)
    tree2.root.right.right.right = TNode(500)

    hashtable = HashTable()
    tree = BinaryTree()
    intersectionList = tree.tree_intersection(tree1, tree2, hashtable)
    print(intersectionList)
    Left join two hash tables.
    """
    result = []
    for key in ht1.keys():
        if key in ht2.keys():
            result.append([key, ht1.getItem(key), ht2.getItem(key)])
        else:
            result.append([key, ht1.getItem(key), None])

    for key in ht2.keys():
        if key not in ht1.keys():
            result.append([key, None, ht2.getItem(key)])
    return result


if __name__ == "__main__":
    ht1 = HashTable()
    ht1.addItem("fond", "enamored")
    ht1.addItem("wrath", "anger")
    ht1.addItem("diligent", "employed")
    ht1.addItem("outfit", "garb")
    ht1.addItem("guide", "usher")

    ht2 = HashTable()
    ht2.addItem("fond", "averse")
    ht2.addItem("wrath", "delight")
    ht2.addItem("diligent", "idle")
    ht2.addItem("guide", "follow")
    ht2.addItem("flow", "jam")

    print(left_join(ht1, ht2))
def test_left_join_hashmap():
    ht1 = HashTable()
    ht1.addItem("fond", "enamored")
    ht1.addItem("wrath", "anger")
    ht1.addItem("diligent", "employed")
    ht1.addItem("outfit", "garb")
    ht1.addItem("guide", "usher")

    ht2 = HashTable()
    ht2.addItem("fond", "averse")
    ht2.addItem("wrath", "delight")
    ht2.addItem("diligent", "idle")
    ht2.addItem("guide", "follow")
    ht2.addItem("flow", "jam")

    assert left_join(ht1, ht2) == [['fond', 'enamored', 'averse'],
                                   ['guide', 'usher', 'follow'],
                                   ['wrath', 'anger', 'delight'],
                                   ['outfit', 'garb', None],
                                   ['diligent', 'employed', 'idle'],
                                   ['flow', None, 'jam']]
def test_hash_function():
    """test the hashing function"""
    table = HashTable()
    assert table.get_hash("hello") == 532
def test_delete_item():
    """test delete item from the hash table"""
    table = HashTable()
    table.addItem("hello", 15)
    table.deleteItem("hello")
    assert len(table.arr[table.get_hash("hello")]) == 0
def test_contains_item():
    """test check if key is inside the hash table"""
    table = HashTable()
    table.addItem("hello", 15)
    assert table.containsItem("hello")
def test_get_item():
    """test get the value from the hash table"""
    table = HashTable()
    table.addItem("hello", 15)
    assert table.getItem("hello") == 15
def test_add_item():
    """test add item to the hash table"""
    table = HashTable()
    table.addItem("hello", 15)
    assert len(table.arr[table.get_hash("hello")]) == 1