feat: add example usage of comparator

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-07 15:42:06 +02:00
parent e50cca7a14
commit 457ab180d0
Signed by: mfocko
GPG Key ID: 7C47D46246790496
1 changed files with 47 additions and 0 deletions

47
comparator_usage.py Normal file
View File

@ -0,0 +1,47 @@
from comparator import Comparator
from avl import AVLTree
from wavl import WAVLTree
import logging
import random
def main():
logging.basicConfig(level=logging.DEBUG)
t = Comparator(AVLTree(), WAVLTree())
# t = WAVLTree()
values = []
for _ in range(42):
x = random.randint(1, 100)
while x in values:
x = random.randint(1, 100)
values.append(x)
t.insert(x)
for _ in range(5):
x = random.choice(values)
values.remove(x)
t.delete(x)
for _ in range(42):
x = random.randint(1, 100)
while x in values:
x = random.randint(1, 100)
values.append(x)
t.insert(x)
for _ in range(5):
x = random.choice(values)
values.remove(x)
t.delete(x)
print(t)
# print(t.are_equal)
if __name__ == "__main__":
main()