forked from UNN/2026-rff_mp
[1] add basic tests for all structures
This commit is contained in:
parent
d263bab16d
commit
20cf87fb40
|
|
@ -51,7 +51,7 @@ def ll_list_all(head):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# хеш-функция – сумма ord(name) % size
|
# хеш-функция: сумма ord(name) % size
|
||||||
def _hash(name, size):
|
def _hash(name, size):
|
||||||
h = 0
|
h = 0
|
||||||
for ch in name:
|
for ch in name:
|
||||||
|
|
@ -182,3 +182,36 @@ def bst_list_all(root):
|
||||||
inorder(node['r'])
|
inorder(node['r'])
|
||||||
inorder(root)
|
inorder(root)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# TESTING
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print("=== Linked list test ===")
|
||||||
|
head = None
|
||||||
|
head = ll_insert(head, "Ivan", "111")
|
||||||
|
head = ll_insert(head, "Anna", "222")
|
||||||
|
head = ll_insert(head, "Ivan", "333")
|
||||||
|
print(ll_find(head, "Ivan")) # 333
|
||||||
|
print(ll_list_all(head)) # [('Anna','222'),('Ivan','333')]
|
||||||
|
head = ll_delete(head, "Anna")
|
||||||
|
print(ll_list_all(head)) # [('Ivan','333')]
|
||||||
|
|
||||||
|
print("\n=== Hash table test ===")
|
||||||
|
buckets = ht_create()
|
||||||
|
ht_insert(buckets, "Ivan", "111")
|
||||||
|
ht_insert(buckets, "Boris", "444")
|
||||||
|
print(ht_find(buckets, "Ivan")) # 111
|
||||||
|
print(ht_list_all(buckets)) # [('Boris','444'),('Ivan','111')]
|
||||||
|
|
||||||
|
print("\n=== BST test ===")
|
||||||
|
root = None
|
||||||
|
root = bst_insert(root, "Ivan", "111")
|
||||||
|
root = bst_insert(root, "Anna", "222")
|
||||||
|
root = bst_insert(root, "Ivan", "333")
|
||||||
|
print(bst_find(root, "Ivan")) # 333
|
||||||
|
print(bst_list_all(root)) # [('Anna','222'),('Ivan','333')]
|
||||||
Loading…
Reference in New Issue
Block a user