예제 #1
0
    def test_find(self):

        ll = Linked_list(array)
        #pdb.set_trace()
        assert ll.find(lambda item: item == 1) == 1
        assert ll.find(lambda item: item < 2) == 1
        assert ll.find(lambda item: item > 3) == 4
        assert ll.find(lambda item: item == 7) is None
예제 #2
0
    def test_delete_node_in_middle(self):
        ll = Linked_list(array)
        item = 4
        current_node = ll.head
        previous_node = current_node
        while current_node is not None:

            if current_node.data == item:
                current_node = current_node.next
                previous_node.next = current_node

            previous_node = current_node
            current_node = current_node.next

        assert ll.find(lambda item: item == 4) is None
예제 #3
0
    def test_replace(self):

        ll = Linked_list(array)
        newItem = Node(8)
        replaceItem = 6

        current = ll.head
        previous = current

        while current:
            if current.data == replaceItem:
                current = current.next
                previous.next = newItem
                newItem.next = current
                break
            previous = current
            current = current.next
        assert (ll.find(lambda item: item == 8)) == 8
        assert (ll.find(lambda item: item == 6)) == None