forked from DataStories-UniPi/miniDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtree_test.py
More file actions
42 lines (31 loc) · 673 Bytes
/
btree_test.py
File metadata and controls
42 lines (31 loc) · 673 Bytes
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
from btree import Btree
from random import randrange
import random
'''
Test the Btree
'''
NUM = 60
B = 6
lst = []
print(f"Branching factor: {B}")
insertcounter = 0
while len(lst)!=NUM:
new_v = randrange(100)
if new_v not in lst:
lst.append(new_v)
insertcounter += 1
print(f"Inserted {insertcounter} items")
bt = Btree(B)
for ind, el in enumerate(lst):
bt.insert(el, ind)
delcounter = 0
listLength = len(lst)
for i in range(len(lst)):
delvalue = random.choice(lst)
lst.remove(delvalue)
bt.delete(delvalue)
# if counter >= listLength/2:
# break
delcounter += 1
print(f"Deleted {delcounter} items")
bt.plot()