-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (35 loc) · 1019 Bytes
/
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
from pqtree import P, Q
def basic_test():
print("Test 1")
p = P([1, Q([4, 5]), 3])
print("Before reverse:\n",p)
p.reverse()
print("After:\n",p)
print(p.number_of_children())
print(type(p.get_children()[2]))
def flatten_test():
print("Test 2")
p = P([P([1, 2, 3, Q([4, 5])])])
print("Not flattened:",p)
print("Flattened", p.flatten())
q = Q([p, 6, 7])
print("Not flattened:",q)
print("Flattened", q.flatten())
t = q.flatten()
t.reverse()
print(t.get_children())
def ordering_test():
p = Q([[1,2], [2,3], P([[2,4], [2,8], [2,9]])])
print("Ordering:", p.ordering())
def cardinality_test():
p = P([1,2,3,4,5])
q = Q([1,2,3,4,5])
print("Cardinality:", p.cardinality())
print("Cardinality:", q.cardinality())
p = P([1, 2, 3, Q([4, 5, 6]), P([7, 8, 9])])
print("Cardinality:", p.cardinality())
if __name__ == '__main__':
basic_test()
flatten_test()
ordering_test()
cardinality_test()