def test_binary_search_tree():
    tree = BinarySearchTree(30)
    tree.insert(20)
    tree.insert(35)
    tree.insert(10)
    tree.insert(25)

    assert inorder(tree) == [10, 20, 25, 30, 35]
Exemplo n.º 2
0
def test_random_node_special_bst():
    tree = SpecialBinarySearchTree(30)
    tree.insert(20)
    tree.insert(35)
    tree.insert(10)

    node = tree.get_random_node()

    assert node in inorder(tree)
def test_find_binary_search_tree():
    tree = BinarySearchTree(30)
    tree.insert(20)
    tree.insert(35)
    tree.insert(10)
    tree.insert(25)

    found_tree = tree.find(20)

    assert inorder(found_tree) == [10, 20, 25]
Exemplo n.º 4
0
def is_binary_search_tree(tree):
    values = inorder(tree)
    copied_values = values.copy()
    copied_values.sort()
    return values == copied_values
 def __eq__(self, rhs):
     return inorder(self) == inorder(rhs)
Exemplo n.º 6
0
def test_inorder_traversal_create_min_tree():
    tree = create_min_tree([1, 2, 3, 4, 5])

    result = inorder(tree)

    assert result == [1, 2, 3, 4, 5]
Exemplo n.º 7
0
def test_inorder(tree):
    values = inorder(tree, [])

    assert values == [2, 1, 5, 7, 4]