Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from BinarySearchTree import BinarySearchTree, Node
- import random, string
- # MAKE CHANGES AND DO YOUR OWN TESTING
- def randomword():
- letters = string.ascii_lowercase
- return ''.join(random.choice(letters) for i in range(random.randint(0,12)))
- def main():
- bst = BinarySearchTree()
- bst.insert(5, "Dasher")
- bst.insert(9, "Dancer")
- bst.insert(4, "Prancer")
- bst.insert(12, "Vixen")
- bst.insert(7, "Comet")
- bst.insert(2, "Cupid")
- print("-----TEST 1-----\n ", bst.inorder(bst.root, []), "\n Root ", bst.root, "\n")
- bst.insert(8, "Donner")
- bst.insert(3, "Blitzen")
- bst.remove(12) # Remove a leaf
- print("-----TEST 2-----\n ", bst.inorder(bst.root, []), "\n Root ", bst.root, "\n")
- bst.insert(6, "Rudolph")
- bst.remove(5) # Remove the root
- print("-----TEST 3-----\n ", bst.inorder(bst.root, []), "\n Root\t", bst.root, "\n")
- print("-----TEST 4-----\n ", bst.inorder(bst.root, []), "\n Root\t", bst.root)
- # Test the other functions
- print(" Find\t", bst.find_name(7))
- print(" Min\t", bst.min(bst.root))
- print(" Max\t", bst.max(bst.root))
- print(" Size\t", bst.get_size())
- print("")
- bst.insert(2, "Cupid") # Update a value
- for i in range(0, 500):
- bst.remove(i)
- count = 1
- for i in range(0, 2000):
- randkey = random.randint(0, 1000)
- randword = randomword()
- if randkey and randword:
- bst.insert(randkey, randword)
- if i%200 == 0:
- print("-----custom test -- insert {}-----\n ".format(count), bst.inorder(bst.root, []), "\n Root\t", bst.root)
- count += 1
- print("\n")
- count = 1
- for i in range(0, 100000):
- randkey = random.randint(0, 200)
- randword = randomword()
- if bst.root:
- if i % random.randint(1, 500) == 0:
- bst.remove(bst.root.key)
- bst.insert(randkey, randword)
- bst.remove(i)
- # if i % 200 == 0:
- # print("-----custom test -- remove {}-----\n ".format(count), bst.inorder(bst.root, []), "\n Root\t", bst.root)
- # count += 1
- print("\n")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement