def test_add_lesser_to_not_empty_bst():
    tree = BinarySearchTree()
    tree.add(5)
    tree.add(2)
    actual = tree.root.left.value
    expected = 2
    assert actual == expected
def test_add_greater_to_not_empty_bst():
    tree = BinarySearchTree()
    tree.add(5)
    tree.add(7)
    actual = tree.root.right.value
    expected = 7
    assert actual == expected
def test_breadth_first_can_display_correct_order():
    tree1 = BinarySearchTree()
    input1 = [10, 15, 8, 6, 14, 20]
    for item in input1:
        tree1.add(item)
    actual = breadth_first(tree1)
    expected = [10, 8, 15, 6, 14, 20]
    assert actual == expected
def new_tree():
    new_tree = BinarySearchTree()
    new_tree.add(20)
    new_tree.add(15)
    new_tree.add(25)
    new_tree.add(12)
    new_tree.add(17)
    new_tree.add(23)
    new_tree.add(28)
    return new_tree
def test_bst_contains():
    tree = BinarySearchTree()
    tree.add(5)
    tree.add(10)
    tree.add(6)
    tree.add(7)
    actual = tree.contains(7)
    expected = True
    assert actual == expected
def test_add_greater_then_in_between():
    tree = BinarySearchTree()
    tree.add(5)
    tree.add(10)
    tree.add(7)
    actual = tree.root.right.left.value
    expected = 7
    assert actual == expected
Ejemplo n.º 7
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
def test_post_order():
    tree = BinarySearchTree()
    tree.add(50)
    tree.add(25)
    tree.add(75)
    tree.add(20)
    tree.add(80)
    tree.add(40)

    """
                50
            25      75
        20    40          80
    """

    actual = tree.post_order()
    expected = [20, 40, 25, 80, 75, 50]
    assert actual == expected
def test_add_lesser_then_in_between():
    tree = BinarySearchTree()
    tree.add(5)
    tree.add(2)
    tree.add(3)
    actual = tree.root.left.right.value
    expected = 3
    assert actual == expected
def test_add_method_will_add_to_tree():
    tree = BinarySearchTree()
    tree.add(10)
    tree.add(15)
    tree.add(5)
    assert tree.root.value == 10
    assert tree.root.right.value == 15
    assert tree.root.left.value == 5
Ejemplo n.º 11
0
def test_tree_one_member():
    tree = BinarySearchTree()
    tree.add('apples')
    assert tree._root.value == 'apples'
Ejemplo n.º 12
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_can_instantiate_a_binary_search_tree():
    tree1 = BinarySearchTree()
    tree1.root == None
def test_add_to_empty_bst_again():
    tree = BinarySearchTree()
    tree.add(7)
    actual = tree.root.value
    expected = 7
    assert actual == expected
def test_binary_search_tree_has_root():
    tree = BinarySearchTree()
    assert tree.root is None
def test_create_binary_search_tree():
    tree = BinarySearchTree()
    assert tree
def test_breadth_first_can_account_for_one_node():
    tree1 = BinarySearchTree()
    tree1.add(7)
    actual = breadth_first(tree1)
    assert actual == [7]
def test_breadth_first_can_account_for_empty_tree():
    tree1 = BinarySearchTree()
    actual = breadth_first(tree1)
    assert actual == []