added some recursive datastructures
This commit is contained in:
77
recursion/recursive_datastructure/solution/test_lists.py
Normal file
77
recursion/recursive_datastructure/solution/test_lists.py
Normal file
@ -0,0 +1,77 @@
|
||||
from lists import LinkedList
|
||||
|
||||
def test_append():
|
||||
lst = LinkedList[int]()
|
||||
lst.append(1)
|
||||
lst.append(2)
|
||||
lst.append(3)
|
||||
lst.append(4)
|
||||
lst2 = LinkedList[int]()
|
||||
lst2.append(1)
|
||||
lst2.append(2)
|
||||
lst2.append(3)
|
||||
lst2.append(4)
|
||||
assert lst == lst2
|
||||
|
||||
def test_remove():
|
||||
lst = LinkedList[int]()
|
||||
lst.remove(0)
|
||||
lst.append(1)
|
||||
lst.append(2)
|
||||
lst.append(3)
|
||||
lst.append(4)
|
||||
lst.remove(2)
|
||||
lst.remove(5)
|
||||
lst2 = LinkedList[int]()
|
||||
lst2.append(1)
|
||||
lst2.append(3)
|
||||
lst2.append(4)
|
||||
assert lst == lst2
|
||||
|
||||
def test_length():
|
||||
lst = LinkedList[int]()
|
||||
lst.append(0)
|
||||
lst.append(1)
|
||||
lst.append(2)
|
||||
lst.append(3)
|
||||
lst.append(4)
|
||||
assert len(lst) == 5
|
||||
lst.remove(0)
|
||||
assert len(lst) == 4
|
||||
lst.remove(2)
|
||||
assert len(lst) == 3
|
||||
lst.remove(1)
|
||||
assert len(lst) == 2
|
||||
lst.remove(3)
|
||||
assert len(lst) == 1
|
||||
lst.remove(4)
|
||||
assert len(lst) == 0
|
||||
lst.remove(4)
|
||||
lst.remove(5)
|
||||
assert len(lst) == 0
|
||||
|
||||
|
||||
def test_index():
|
||||
lst = LinkedList[int]()
|
||||
lst.append(0)
|
||||
lst.append(1)
|
||||
lst.append(2)
|
||||
lst.append(3)
|
||||
lst.append(4)
|
||||
assert lst[0] == 0
|
||||
assert lst[1] == 1
|
||||
assert lst[2] == 2
|
||||
assert lst[3] == 3
|
||||
assert lst[4] == 4
|
||||
|
||||
def test_iter():
|
||||
lst = LinkedList[int]()
|
||||
lst.append(0)
|
||||
lst.append(1)
|
||||
lst.append(2)
|
||||
lst.append(3)
|
||||
lst.append(4)
|
||||
j = 0
|
||||
for i in iter(lst):
|
||||
assert i == j
|
||||
j += 1
|
Reference in New Issue
Block a user