@@ -8,60 +8,58 @@ def test_binary_tree(self):
8
8
data = [10 , 5 , 15 , 4 , 7 , 13 , 17 , 11 , 14 ]
9
9
# create 2 trees with the same content
10
10
bt = binary_tree .BinaryTree ()
11
- root = binary_tree .bt_insert (bt .get_root (), data [0 ])
12
- for i in data [1 :]:
13
- binary_tree .bt_insert (root , i )
11
+ for i in data :
12
+ bt .insert (i )
14
13
15
14
bt2 = binary_tree .BinaryTree ()
16
- root2 = binary_tree .bt_insert (bt2 .get_root (), data [0 ])
17
- for i in data [1 :]:
18
- binary_tree .bt_insert (root2 , i )
15
+ for i in data :
16
+ bt2 .insert (i )
19
17
20
18
# check if both trees are identical
21
- self .assertTrue (binary_tree . bt_compare_trees ( root , root2 ))
19
+ self .assertTrue (bt . compare_trees ( bt2 . get_root () ))
22
20
23
21
# check the content of the tree inorder
24
22
t = []
25
- for d in binary_tree . bt_tree_data ( root ):
23
+ for d in bt . tree_data ( ):
26
24
t .append (d )
27
25
self .assertEquals (t , [4 , 5 , 7 , 10 , 11 , 13 , 14 , 15 , 17 ])
28
26
29
27
# test lookup
30
- node , parent = binary_tree . bt_lookup ( root , 9 )
28
+ node , parent = bt . lookup ( 9 )
31
29
self .assertTrue (node == None )
32
- node , parent = binary_tree . bt_lookup ( root , 11 )
30
+ node , parent = bt . lookup ( 11 )
33
31
self .assertTrue (node .data == 11 )
34
32
self .assertTrue (parent .data == 13 )
35
33
36
34
# delete a leaf node
37
- binary_tree . bt_delete ( root , 4 )
35
+ bt . delete ( 4 )
38
36
# check the content of the tree inorder
39
37
t = []
40
- for d in binary_tree . bt_tree_data ( root ):
38
+ for d in bt . tree_data ( ):
41
39
t .append (d )
42
40
self .assertEquals (t , [5 , 7 , 10 , 11 , 13 , 14 , 15 , 17 ])
43
41
44
42
# delete a node with 1 child
45
- binary_tree . bt_delete ( root , 5 )
43
+ bt . delete ( 5 )
46
44
# check the content of the tree inorder
47
45
t = []
48
- for d in binary_tree . bt_tree_data ( root ):
46
+ for d in bt . tree_data ( ):
49
47
t .append (d )
50
48
self .assertEquals (t , [7 , 10 , 11 , 13 , 14 , 15 , 17 ])
51
49
52
50
# delete a node with 2 childs
53
- binary_tree . bt_delete ( root , 13 )
51
+ bt . delete ( 13 )
54
52
# check the content of the tree inorder
55
53
t = []
56
- for d in binary_tree . bt_tree_data ( root ):
54
+ for d in bt . tree_data ( ):
57
55
t .append (d )
58
56
self .assertEquals (t , [7 , 10 , 11 , 14 , 15 , 17 ])
59
57
60
58
# delete a node with 2 childs
61
- binary_tree . bt_delete ( root , 15 )
59
+ bt . delete ( 15 )
62
60
# check the content of the tree inorder
63
61
t = []
64
- for d in binary_tree . bt_tree_data ( root ):
62
+ for d in bt . tree_data ( ):
65
63
t .append (d )
66
64
self .assertEquals (t , [7 , 10 , 11 , 14 , 17 ])
67
65
0 commit comments