Skip to content

Commit 1b2d32d

Browse files
committed
BST done() :)
1 parent 1159b98 commit 1b2d32d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pydatastructs/trees/tests/test_binary_trees.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def test_cpp_BST2():
4646
BST = BinarySearchTree
4747
b = BST(8, 8, backend=Backend.CPP)
4848
# b = BST(8, 8)
49+
50+
##### insert() and delete() tests #####
4951
b.delete(8)
5052
b.insert(8, 8)
5153
b.insert(3, 3)
@@ -62,11 +64,13 @@ def test_cpp_BST2():
6264
"(5, 6, 6, 6), (None, 4, 4, None), (None, 7, 7, None), (8, 14, 14, None), "
6365
"(None, 13, 13, None)]")
6466

67+
##### _simple_path() test #####
6568
path = b._simple_path(1,0)
6669
assert path[0] == 0
6770
assert path[1] == 1
6871
assert path[2] == 3
6972

73+
##### search() and delete() tests #####
7074
assert b.search(10) == 2
7175
assert b.search(-1) is None
7276
assert b.delete(13) is True
@@ -116,6 +120,7 @@ def test_cpp_BST2():
116120
bl1.insert(node, node)
117121
assert str(bl1) == "[(1, 50, 50, 2), (8, 30, 30, 9), (3, 90, 90, 4), (5, 70, 70, 6), (None, 100, 100, None), (7, 60, 60, None), (None, 80, 80, None), (None, 55, 55, None), (10, 20, 20, None), (None, 40, 40, None), (11, 15, 15, 12), (None, 10, 10, None), (None, 16, 16, 13), (None, 17, 17, 14), (None, 18, 18, None)]"
118122

123+
##### lowest common ancestor _lca2_() tests #####
119124
assert bl1.lowest_common_ancestor(80, 55, 2) == 70
120125
assert bl1.lowest_common_ancestor(60, 70, 2) == 70
121126
assert bl1.lowest_common_ancestor(18, 18, 2) == 18
@@ -137,6 +142,7 @@ def test_cpp_BST2():
137142
bl2.insert(node, node)
138143
assert str(bl2) == "[(1, 50, 50, 2), (8, 30, 30, 9), (3, 90, 90, 4), (5, 70, 70, 6), (None, 100, 100, None), (7, 60, 60, None), (None, 80, 80, None), (None, 55, 55, None), (10, 20, 20, None), (None, 40, 40, None), (11, 15, 15, 12), (None, 10, 10, None), (None, 16, 16, 13), (None, 17, 17, 14), (None, 18, 18, None)]"
139144

145+
##### lowest common ancestor _lca1_() tests #####
140146
assert bl2.lowest_common_ancestor(80, 55, 1) == 70
141147
assert bl2.lowest_common_ancestor(60, 70, 1) == 70
142148
assert bl2.lowest_common_ancestor(18, 18, 1) == 18
@@ -151,13 +157,15 @@ def test_cpp_BST2():
151157
assert raises(ValueError, lambda: bl2.lowest_common_ancestor(200, 60, 1))
152158
assert raises(ValueError, lambda: bl2.lowest_common_ancestor(-3, 4, 1))
153159

160+
##### rank() tests #####
154161
assert bl2.rank(18) == 5
155162
assert bl2.rank(10) == 1
156163
rank_list = [2, 2, 4, 4, 5, 4, 5, 3, 2, 3, 2, 1, 3, 4, 5]
157164
for i,node in enumerate(nodes):
158165
assert bl2.rank(node) == rank_list[i]
159166
assert bl2.rank(200) is None
160167

168+
##### select() tests #####
161169
select_list = [10, 50, 55, 90, 100]
162170
for i in range(5):
163171
assert bl2.select(i+1).key == select_list[i]
@@ -167,17 +175,20 @@ def test_cpp_BST2():
167175
b3.insert(10, 10)
168176
b3.insert(18, 18)
169177
b3.insert(7, 7)
178+
179+
##### upper_bound() tests #####
170180
assert b3.upper_bound(9) == 10
171181
assert b3.upper_bound(7) == 10
172182
assert b3.upper_bound(-1) == 7
173183
assert b3.upper_bound(20) is None
174184

185+
##### lower_bound() tests #####
175186
assert b3.lower_bound(9) == 10
176187
assert b3.lower_bound(7) == 7
177188
assert b3.lower_bound(-1) == 7
178189
assert b3.lower_bound(20) is None
179190

180-
test_cpp_BST2()
191+
# test_cpp_BST2()
181192

182193
def test_cpp_BST_speed():
183194
BST = BinarySearchTree

0 commit comments

Comments
 (0)