Exemplo n.º 1
0
def setup_left_right_heavy_tree():
    x = AVLTree()
    x.add(4)
    x.add(3)
    x.add(1)
    x.add(2)
    return x
Exemplo n.º 2
0
def setup_multiple_adds():
    x = AVLTree()
    x.add(1)
    x.add(2)
    x.add(3)
    x.add(4)
    x.add(5)
    x.add(6)
    x.add(7)
    x.add(8)
    return x
Exemplo n.º 3
0
def test_node_rebalance_right_left_balance():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.balance is 0
Exemplo n.º 4
0
def test_node_rebalance_right_left_structure():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.value is 13
    assert x.head_node.left_node.value is 10
    assert x.head_node.right_node.value is 15
Exemplo n.º 5
0
def setup_multiple_adds():
    x = AVLTree()
    x.add(1)
    x.add(2)
    x.add(3)
    x.add(4)
    x.add(5)
    x.add(6)
    x.add(7)
    x.add(8)
    return x
Exemplo n.º 6
0
def test_node_rebalance_right_left_balance():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.balance is 0
Exemplo n.º 7
0
def test_node_rebalance_right_left_depth():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.right_depth is 1
    assert x.head_node.left_depth is 1
    assert x.head_node.right_node.left_depth is 0
    assert x.head_node.right_node.right_depth is 0
    assert x.head_node.left_node.left_depth is 0
    assert x.head_node.left_node.right_depth is 0
Exemplo n.º 8
0
def test_node_rebalance_right_left_structure():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.value is 13
    assert x.head_node.left_node.value is 10
    assert x.head_node.right_node.value is 15
Exemplo n.º 9
0
def test_node_rebalance_right_right_structure():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(1)
    x.add(5)
    x.add(10)
    assert x.head_node.value is 5
    assert x.head_node.left_node.value is 1
    assert x.head_node.right_node.value is 10
Exemplo n.º 10
0
def test_node_rebalance_right_left_depth():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(10)
    x.add(15)
    x.add(13)
    print x.to_string()
    assert x.head_node.right_depth is 1
    assert x.head_node.left_depth is 1
    assert x.head_node.right_node.left_depth is 0
    assert x.head_node.right_node.right_depth is 0
    assert x.head_node.left_node.left_depth is 0
    assert x.head_node.left_node.right_depth is 0
Exemplo n.º 11
0
def setup_left_right_heavy_tree():
    x = AVLTree()
    x.add(4)
    x.add(3)
    x.add(1)
    x.add(2)
    return x
Exemplo n.º 12
0
def test_node_rebalance_right_right_depth():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(1)
    x.add(5)
    x.add(10)
    assert x.head_node.right_depth is 1
    assert x.head_node.left_depth is 1
    assert x.head_node.right_node.left_depth is 0
    assert x.head_node.right_node.right_depth is 0
    assert x.head_node.left_node.left_depth is 0
    assert x.head_node.left_node.right_depth is 0
Exemplo n.º 13
0
def test_node_rebalance_right_right_structure():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(1)
    x.add(5)
    x.add(10)
    assert x.head_node.value is 5
    assert x.head_node.left_node.value is 1
    assert x.head_node.right_node.value is 10
Exemplo n.º 14
0
def test_node_rebalance_right_right_depth():
    x = AVLTree()
    x.head_node = AVLNode()
    x.add(1)
    x.add(5)
    x.add(10)
    assert x.head_node.right_depth is 1
    assert x.head_node.left_depth is 1
    assert x.head_node.right_node.left_depth is 0
    assert x.head_node.right_node.right_depth is 0
    assert x.head_node.left_node.left_depth is 0
    assert x.head_node.left_node.right_depth is 0
Exemplo n.º 15
0
def test_delete_empty_tree_false():
    x = AVLTree()
    assert x.delete(1) is False
Exemplo n.º 16
0
def test_empty_tree():
    x = AVLTree()
    assert x.head_node is None
Exemplo n.º 17
0
def test_delete_empty_tree_false():
    x = AVLTree()
    assert x.delete(1) is False
Exemplo n.º 18
0
def setup_one_add():
    x = AVLTree()
    x.add(1)
    return x
Exemplo n.º 19
0
def setup_two_adds_right():
    x = AVLTree()
    x.add(1)
    x.add(2)
    return x
Exemplo n.º 20
0
def setup_two_adds_right():
    x = AVLTree()
    x.add(1)
    x.add(2)
    return x
Exemplo n.º 21
0
def setup_complicated_delete():
    x = AVLTree()
    x.add(50)
    x.add(25)
    x.add(75)
    x.add(15)
    x.add(40)
    x.add(60)
    x.add(80)
    x.add(35)
    x.add(55)
    x.add(65)
    x.add(90)
    x.add(62)
    return x
Exemplo n.º 22
0
def setup_one_add():
    x = AVLTree()
    x.add(1)
    return x
Exemplo n.º 23
0
def setup_complicated_delete():
    x = AVLTree()
    x.add(50)
    x.add(25)
    x.add(75)
    x.add(15)
    x.add(40)
    x.add(60)
    x.add(80)
    x.add(35)
    x.add(55)
    x.add(65)
    x.add(90)
    x.add(62)
    return x
Exemplo n.º 24
0
def setup_two_adds_left():
    x = AVLTree()
    x.add(2)
    x.add(1)
    return x
Exemplo n.º 25
0
from DataStructures.AVLTree import AVLTree

tree = AVLTree()

tree.insert(1)
tree.insert(2)
tree.insert(3)
tree.insert(4)
tree.insert(5)
tree.insert(6)

tree.traverseInOrder()

tree = AVLTree()

tree.insert(5)
tree.insert(7)
tree.insert(6)


tree.traverseInOrder()
Exemplo n.º 26
0
def setup_two_adds_left():
    x = AVLTree()
    x.add(2)
    x.add(1)
    return x