def prepare_bst():
    bst = BinarySearchTree()
    bst.add(23)
    bst.add(8)
    bst.add(4)
    bst.add(42)
    bst.add(27)
    return bst
Exemple #2
0
def test_add_three_members():
    tree = BinarySearchTree()
    tree.add(10)
    tree.add(5)
    tree.add(15)
    assert tree._root.value == 10
    assert tree._root.left.value == 5
    assert tree._root.right.value == 15
Exemple #3
0
def test_add_a_left_child_and_right_child_to_a_single_root_node():
    bst = BinarySearchTree()
    bst.add(4)
    bst.add(3)
    bst.add(5)
    expected = [3, 4, 5]
    actual = bst.inOrder()
    assert actual == expected
def test_tow_same_tree():
    tree7 = BinarySearchTree()
    tree7.add(6)
    tree7.add(5)
    tree7.add(1)
    tree7.add(45)
    tree7.add(10)
    tree7.add(16)
    tree7.add(5)
    tree8 = BinarySearchTree()
    tree8.add(6)
    tree8.add(5)
    tree8.add(1)
    tree8.add(45)
    tree8.add(10)
    tree8.add(16)
    tree8.add(5)
    assert tree_intersection(tree7, tree8) == [6, 5, 45, 1, 5, 10, 16]
Exemple #5
0
def fixed_tree_with_elements():
    tree=BinarySearchTree()
    tree.add(7)
    tree.add(9)
    tree.add(5)
    tree.add(11)
    tree.add(8)
    tree.add(1)
    return tree
Exemple #6
0
def fixed_tree_with_elements_2():
    tree=BinarySearchTree()
    tree.add(23)
    tree.add(43)
    tree.add(34)
    tree.add(67)
    tree.add(56)
    tree.add(89)
    return tree
def test_no_similar_leafs():
    tree5 = BinarySearchTree()
    tree5.add(4)
    tree5.add(6)
    tree5.add(7)
    tree5.add(5)
    tree5.add(3)
    tree5.add(3)
    tree5.add(2)
    tree6 = BinarySearchTree()
    tree6.add(6)
    tree6.add(5)
    tree6.add(1)
    tree6.add(45)
    tree6.add(10)
    tree6.add(16)
    tree6.add(5)
    assert tree_intersection(tree5, tree6) == None
Exemple #8
0
def my_bst():
    tree = BinarySearchTree()
    tree.add(15)
    tree.add(11)
    tree.add(13)
    tree.add(7)
    tree.add(8)
    tree.add(5)
    tree.add(19)
    tree.add(17)
    tree.add(23)
    return tree
def test_breadth_first_bst():
    bst = BinarySearchTree()
    bst.add(4)
    bst.add(9)
    bst.add(-1)
    bst.add(6)
    bst.add(3)
    bst.add(8)
    bst.add(5)
    actual = bst.breadth_first(bst)
    expected = [4, 9, 6, 8, 5, -1, 3]
    assert actual == expected
Exemple #10
0
def test_add_more_members_for_balanced():
    tree = BinarySearchTree()
    tree.add(15)
    tree.add(11)
    tree.add(13)
    tree.add(7)
    tree.add(25)
    tree.add(60)
    tree.add(23)
    assert tree._root.value == 15
    assert tree._root.left.value == 11
    assert tree._root.right.value == 25
    assert tree._root.left.left.value == 7
    assert tree._root.left.right.value == 13
    assert tree._root.right.right.value == 60
    assert tree._root.right.left.value == 23
Exemple #11
0
def test_addfor_balanced():
    tree = BinarySearchTree()
    tree.add(15)
    tree.add(11)
    tree.add(13)
    tree.add(7)
    tree.add(25)
    tree.add(60)
    tree.add(23)
    assert tree._root.data == 15
    assert tree._root.left.data == 11
    assert tree._root.right.data == 25
    assert tree._root.left.left.data == 7
    assert tree._root.left.right.data == 13
    assert tree._root.right.right.data == 60
    assert tree._root.right.left.data == 23
def test_difrent_tree_type():
    tree3 = BinaryTree()
    tree3.root = Node(5)
    tree3.root.right = Node(6)
    tree3.root.left = Node(4)
    tree3.root.right.right = Node(7)
    tree3.root.right.left = Node(5)
    tree3.root.left.left = Node(2)
    tree3.root.left.right = Node(4)
    tree4 = BinarySearchTree()
    tree4.add(4)
    tree4.add(6)
    tree4.add(7)
    tree4.add(5)
    tree4.add(3)
    tree4.add(3)
    tree4.add(2)
    actual = tree_intersection(tree3, tree4)
    expected = [6, 2, 5, 7]
    assert actual == expected
Exemple #13
0
def test_breadth_3():
    tree=BinarySearchTree()
    assert tree.breadth_first() == 'Empty Tree'
Exemple #14
0
def test_empty_tree():  
    new_tree = BinarySearchTree()
    assert new_tree.root == None
Exemple #15
0
def fixed_tree():
    tree=BinarySearchTree()
    return tree
Exemple #16
0
def test_tree_one_member():
    tree = BinarySearchTree()
    tree.add('apples')
    assert tree._root.value == 'apples'
Exemple #17
0
def test_pre_order_one():
    tree_one = BinarySearchTree()
    tree_one.add(20)
    assert tree_one.pre_order() == [20]
Exemple #18
0
def test_tree_one_member():
    tree = BinarySearchTree()
    tree.add('hamza')
    assert tree._root.data == 'hamza'
Exemple #19
0
def test_add_one_node():
    tree = BinarySearchTree()
    tree.add(20)
    assert tree._root.value == 20
    assert tree._root.left == None
    assert tree._root.right == None
Exemple #20
0
def test_check_one_node_tree():
    tree = BinarySearchTree()
    tree.add(20)
    assert tree.contains(20) == True
    assert tree.contains(21) == False
def test_bst_add_on_root():
    bst = BinarySearchTree()
    bst.add(4)
    expected = 4
    actual = bst.root.value
    assert actual == expected