-
Notifications
You must be signed in to change notification settings - Fork 39
/
binary_heap_test.py
78 lines (60 loc) · 1.34 KB
/
binary_heap_test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
# -*- encoding=utf-8 -*-
# author: Ian
# e-mail: [email protected]
# description:
import binary_heap
def test():
test_data = [(1, 0), (0.9, 1), (1.1, 2), (1.1, 3), (3.3, 4), (0, 5), (0.93, 6)]
BH = binary_heap.BinaryHeap(7)
# empty queue
print('empty queue')
print(BH)
print('max priority')
print(BH.get_max_priority())
# insert
print('\ntest insert')
for p, i in test_data:
BH.update(p, i)
print(BH)
print(BH.p2e)
print(BH.e2p)
# update
print('\ntest update')
BH.update(9.9, 0)
print(BH)
print(BH.p2e)
print(BH.e2p)
# get max priority
print('\nmax priority')
print(BH.get_max_priority())
# re balance
print('\ntest re_balance')
BH.balance_tree()
print(BH)
print(BH.p2e)
print(BH.e2p)
# full insert
print('\ntest full insert')
BH.update(9.2, 7)
print(BH)
# pop
print('\ntest pop')
p, i = BH.pop()
print('pop out: ', p, i)
print(BH)
print(BH.p2e)
print(BH.e2p)
# get priority
print('\ntest get priority')
print(BH.get_priority())
# get e id
print('\ntest e id')
print(BH.get_e_id())
# p id to e id
print('\ntest p id to e id')
print(BH.priority_to_experience([2, 3, 6]))
def main():
test()
if __name__ == '__main__':
main()