Exemplo n.º 1
0
def bst_full():
    bst_full = BinarySearchTree()
    bst_full.add(15)
    bst_full.add(8)
    bst_full.add(3)
    bst_full.add(5)
    bst_full.add(65)
    return bst_full
def test_BST_post_order_2():
    bst = BinarySearchTree()
    bst.add(50)
    bst.add(60)
    bst.add(55)
    bst.add(40)
    bst.add(45)
    actual = bst.post_order()
    expected = [45, 40, 55, 60, 50]
    assert actual == expected
def test_BST_pre_order():
    bst = BinarySearchTree()
    bst.add(1)
    bst.add(3)
    bst.add(20)
    bst.add(7)
    bst.add(8)
    actual = bst.pre_order()
    expected = [1, 3, 20, 7, 8]
    assert actual == expected
def test_pre():
    bst = BinarySearchTree()
    bst.add(1)
    bst.add(2)
    bst.add(3)
    bst.add(4)
    bst.add(5)
    actual = bst.pre_order()
    expected = [1, 2, 3, 4, 5]
    assert actual == expected
def test_contains():
    bst = BinarySearchTree()
    bst.add(1)
    bst.add(2)
    bst.add(3)
    actual = bst.contains(2)
    expected = True
    assert actual == expected
def test_BST_left_and_right():
    bst = BinarySearchTree()
    bst.add(2)
    bst.add(1)
    bst.add(3)
    right = bst.root.right.value
    expected_right = 3
    left = bst.root.left.value
    expected_left = 1
    assert right == expected_right
    assert left == expected_left
def test_BST_post_order():
    bst = BinarySearchTree()
    bst.add(85)
    bst.add(70)
    bst.add(75)
    bst.add(45)
    bst.add(100)
    bst.add(90)
    bst.add(110)
    actual = bst.post_order()
    expected = [45, 75, 70, 90, 110, 100, 85]
    assert actual == expected
def test_BST_single_root():
    bst = BinarySearchTree()
    bst.add(1337)
    actual = bst.root.value
    expected = 1337
    assert actual == expected
def test_BST_pre_order_2():
    bst = BinarySearchTree()
    bst.add(5)
    bst.add(7)
    bst.add(8)
    bst.add(6)
    bst.add(3)
    bst.add(2)
    bst.add(4)
    actual = bst.pre_order()
    expected = [5, 3, 2, 4, 7, 6, 8]
    assert actual == expected
def test_BST_contains_False():
    bst = BinarySearchTree()
    bst.add(85)
    bst.add(70)
    bst.add(75)
    bst.add(45)
    bst.add(100)
    bst.add(90)
    bst.add(110)
    actual = bst.contains(200)
    expected = False
    assert actual == expected
Exemplo n.º 11
0
def test_BST_instantiation():
    bst = BinarySearchTree()
    actual = str(bst)
    expected = "NULL"
    assert actual == expected
Exemplo n.º 12
0
def test_BST_import():
    BinarySearchTree()
Exemplo n.º 13
0
def test_BST_contains_empty_tree():
    bst = BinarySearchTree()
    actual = bst.contains(44)
    expected = "Binary Search Tree is empty"
    assert actual == expected
Exemplo n.º 14
0
def test_BST_contains_nonInteger():
    bst = BinarySearchTree()
    actual = bst.contains("apples")
    expected = "Binary Search Tree contains only take integers"
    assert actual == expected
Exemplo n.º 15
0
def test_BST_add_nonInteger():
    bst = BinarySearchTree()
    actual = bst.add('apple')
    expected = "Binary Search Tree can only take integers"
    assert actual == expected
def test_in():
    bst = BinarySearchTree()
    bst.add(85)
    bst.add(70)
    bst.add(75)
    bst.add(45)
    bst.add(100)
    bst.add(90)
    bst.add(110)
    actual = bst.in_order()
    expected = [45, 70, 75, 85, 90, 100, 110]
    assert actual == expected