-
Notifications
You must be signed in to change notification settings - Fork 207
/
test_binarytrees.py
62 lines (43 loc) · 1.28 KB
/
test_binarytrees.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from sksurv.bintrees import RBTree, AVLTree
@pytest.fixture(params=[RBTree, AVLTree])
def tree(request):
return request.param(10)
class TestBinaryTree(object):
@staticmethod
def test_insert(tree):
for k in [12, 34, 45, 16, 35, 57]:
tree.insert(k, k)
assert 6 == len(tree)
@staticmethod
def test_count_smaller(tree):
for k in [12, 34, 45, 16, 35, 57]:
tree.insert(k, k)
c, a = tree.count_smaller(12)
assert 0 == c
c, a = tree.count_smaller(16)
assert 1 == c
c, a = tree.count_smaller(34)
assert 2 == c
c, a = tree.count_smaller(35)
assert 3 == c
c, a = tree.count_smaller(45)
assert 4 == c
c, a = tree.count_smaller(57)
assert 5 == c
@staticmethod
def test_count_larger(tree):
for k in [12, 34, 45, 16, 35, 57]:
tree.insert(k, k)
c, a = tree.count_larger(12)
assert 5 == c
c, a = tree.count_larger(16)
assert 4 == c
c, a = tree.count_larger(34)
assert 3 == c
c, a = tree.count_larger(35)
assert 2 == c
c, a = tree.count_larger(45)
assert 1 == c
c, a = tree.count_larger(57)
assert 0 == c