Esempio n. 1
0
def test_print_three_nodes_even():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    x.right_node = AVLNode()
    x.right_node.value = 15
    print x.to_string()
    assert x.to_string(
    ) == "Value: 10\nLeft node->Value: 5\nRight node->Value: 15"
Esempio n. 2
0
def test_print_two_nodes_right():
    x = AVLNode()
    x.value = 10
    x.right_node = AVLNode()
    x.right_node.value = 15
    print x.to_string()
    assert x.to_string() == "Value: 10\nRight node->Value: 15"
Esempio n. 3
0
def test_print_two_nodes_left():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    print x.to_string()
    assert x.to_string() == "Value: 10\nLeft node->Value: 5"
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
def test_print_three_nodes_even():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    x.right_node = AVLNode()
    x.right_node.value = 15
    print x.to_string()
    assert x.to_string() == "Value: 10\nLeft node->Value: 5\nRight node->Value: 15"
Esempio n. 8
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
Esempio n. 9
0
def test_print_two_nodes_right():
    x = AVLNode()
    x.value = 10
    x.right_node = AVLNode()
    x.right_node.value = 15
    print x.to_string()
    assert x.to_string() == "Value: 10\nRight node->Value: 15"
Esempio n. 10
0
def test_print_two_nodes_left():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    print x.to_string()
    assert x.to_string() == "Value: 10\nLeft node->Value: 5"
Esempio n. 11
0
def test_print_four_nodes():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    x.right_node = AVLNode()
    x.right_node.value = 15
    x.left_node.left_node = AVLNode()
    x.left_node.left_node.value = 1
    print x.to_string()
    assert x.to_string() == "Value: 10\nLeft node->Value: 5\nLeft node->Value: 1\nRight node->Value: 15"
Esempio n. 12
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
Esempio n. 13
0
def test_print_single_node():
    x = AVLNode()
    x.value = 10
    assert x.to_string() == "Value: 10"
Esempio n. 14
0
def test_print_four_nodes():
    x = AVLNode()
    x.value = 10
    x.left_node = AVLNode()
    x.left_node.value = 5
    x.right_node = AVLNode()
    x.right_node.value = 15
    x.left_node.left_node = AVLNode()
    x.left_node.left_node.value = 1
    print x.to_string()
    assert x.to_string(
    ) == "Value: 10\nLeft node->Value: 5\nLeft node->Value: 1\nRight node->Value: 15"
Esempio n. 15
0
def test_print_single_node():
    x = AVLNode()
    x.value = 10
    assert x.to_string() == "Value: 10"