def test_insert_and_size():
    tree = TreeNode(0)
    assert tree.size() == 1
    tree.insert(1)
    assert tree.size() == 2
    tree.insert(1)
    assert tree.size() == 2
def test_right_linked_list_four():
    tree = TreeNode(0)
    tree.insert(1)
    tree.insert(2)
    tree.insert(3)
    assert tree.balance() == -3
    tree = tree.rebalance(tree)
    assert tree.balance() == 1
def test_left_linked_list():
    tree = TreeNode(2)
    tree.insert(1)
    tree.insert(0)
    assert tree.balance() == 2
    tree = tree.rebalance(tree)
    assert tree.balance() == 0
    treelist = [n for n in tree.depth_traversal("in")]
    assert treelist == [0, 1, 2]
def test_left_linked_list_four():
    tree = TreeNode(3)
    tree.insert(2)
    tree.insert(1)
    tree.insert(0)
    assert tree.balance() == 3
    assert tree.val == 3
    tree = tree.rebalance(tree)
    assert tree.balance() == -1
    assert tree.val == 1
def test_depth():
    tree = TreeNode(5)
    assert tree.depth() == 1
    tree.insert(1)
    assert tree.depth() == 2
    tree.insert(6)
    assert tree.depth() == 2
    tree.insert(3)
    assert tree.depth() == 3
def test_balance():
    tree = TreeNode(5)
    assert tree.balance() == 0
    tree.insert(1)
    assert tree.balance() == 1
    tree.insert(6)
    assert tree.balance() == 0
    tree.insert(3)
    tree.insert(4)
    assert tree.balance() == 2
def test_complicated():
    tree = TreeNode(50)
    tree.insert(25)
    tree.insert(30)
    tree.insert(27)
    tree.insert(26)
    tree.insert(60)
    tree.insert(70)
    assert tree.balance() == 2
    tree = tree.rebalance(tree)
    assert tree.balance() == 1
def gimme_a_tree():
    vals = [3, 4, 1, 0, 7, 9, 8, 6, 10]
    head = TreeNode(5)
    for v in vals:
        head.insert(v)
    return head
def test_contains():
    tree = TreeNode(0)
    assert tree.contains(2) is False
    tree.insert(2)
    assert tree.contains(2)