def test_insertBefore(): li=LinkedList() li.insert(5) li.insert(7) li.insertBefore(5,1) li.insertBefore(7,1) assert li.head.next.next.value==1 assert li.head.value==1
def test_string_list(): string = LinkedList() string.insert("a") string.insert("b") string.insert("c") #actual = string.__str__() actual = string.toString() print (actual) assert actual == "{ c } -> { b } -> { a } -> NULL"
def test_includes(): string = LinkedList() string.insert("a") string.insert("b") string.insert("c") #string.insert("d") assert string.includes("a") assert string.includes ("d") == False
def test_insert_letters(): string = LinkedList() string.insert("a") string.insert("b") string.insert("c") #string.insert("d") assert string.head.value == "c" assert string.head.next.value == "b" assert string.head.next.next.value =="a"
def test_list_zip(): li = LinkedList() li2 = LinkedList() li.insert(1) li.insert(2) li.insert(8) li2.insert(3) li2.insert(4) li2.insert(5) assert str(zipLists( li, li2)) == '{8} -> {5} -> {2} -> {4} -> {1} -> {3} -> None' assert len(li) + len(li2) == len(zipLists(li, li2))
def test_index(): li=LinkedList() li.insert(5) assert li.index(0)==5 li.insert(7) li.insert(8) assert li.index(0)==5 assert li.index(1)==7 assert li.index(2)==8 assert li.index(3)==None assert li.index(-1)==None assert li.index(4)==None li.insert(10) li.insert(11) assert li.index(2)
def test_insert(): li=LinkedList() li.insert(5) assert len(li)==1
def test_insertAfter(): li=LinkedList() li.insert(5) li.insert(7) li.insertAfter(7,1) assert li.head.next.value==1
def test_str(): li=LinkedList() li.insert(5) li.insert(7) assert str(li)=='{7} -> {5} -> None'
def test_includes(): li=LinkedList() li.insert(5) assert li.includes(5)=='True' assert li.includes(6)=='False'
def test_insert_multiple_nodes(): li=LinkedList() li.insert(5) li.insert(7) assert len(li)==2
def test_head(): li=LinkedList() li.insert(5) li.insert(7) assert li.head.value==7
def zipLists(list1,list2): list3=LinkedList() current1=list1.head current2=list2.head while current1!=None or current2!=None: if current1!=None: list3.append(current1.value) current1=current1.next if current2!=None: list3.append(current2.value) current2=current2.next return list3 if __name__ == "__main__": li=LinkedList() li2=LinkedList() li.insert(1) li.insert(2) li.insert(8) li2.insert(3) li2.insert(4) li2.insert(5) print(li) print(li2) print(zipLists(li,li2))