def test_list_zip_not_equal_length():
    li = LinkedList()
    li2 = LinkedList()
    li.insert(1)
    li.insert(2)
    li.insert(8)
    li2.insert(3)
    li2.insert(4)
    assert str(zipLists(li, li2)) == '{8} -> {4} -> {2} -> {3} -> {1} -> None'
    assert len(li) + len(li2) == len(zipLists(li, li2))
Example #2
0
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
Example #3
0
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"
Example #4
0
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
Example #5
0
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 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
Example #7
0
def test_insertAfter():
    li=LinkedList()
    li.insert(5)
    li.insert(7)
    li.insertAfter(7,1)
    assert li.head.next.value==1
Example #8
0
def test_append():
    li=LinkedList()
    li.append(5)
    li.append(7) 
    assert len(li)==2
    assert li.head.value==5
Example #9
0
def test_str():
    li=LinkedList()
    li.insert(5)
    li.insert(7)
    assert str(li)=='{7} -> {5} -> None'
Example #10
0
def test_instantiate():
    li=LinkedList()
    assert li.head==None
Example #11
0
def test_includes():
    li=LinkedList()
    li.insert(5)
    assert li.includes(5)=='True'
    assert li.includes(6)=='False'
Example #12
0
def test_insert_multiple_nodes():
    li=LinkedList()
    li.insert(5)
    li.insert(7)
    assert len(li)==2
 def add(self, key, value):
     idx = self.get_hash(key)
     if not self.map[idx]:
         self.map[idx] = LinkedList()
     self.map[idx].insert([key, value])
Example #14
0
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 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))
    
Example #16
0
def test_linked_list_creation():
    ll= LinkedList()
    assert ll.head == None
Example #17
0
def test_letters():
    string = LinkedList()
    string.head = Node("a")
    string.head.next= Node("b")    

    assert string.head.next.value =="b"
Example #18
0
def test_insert():
    li=LinkedList()
    li.insert(5)
    assert len(li)==1
Example #19
0
def test_head():
    li=LinkedList()
    li.insert(5)
    li.insert(7)
    assert li.head.value==7