コード例 #1
0
def test_append():
    L = LinkedList()
    L.append_list("a")
    L.append_list("b")
    L.append_list("c")
    actual = L.value_list()
    print(actual)
    expected = ["a", "b", "c"]
    assert actual == expected
コード例 #2
0
def test_insert_after_2():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(3)
    ll.insert(1)
    ll.insert_after(2, 5)
    actual = str(ll)
    expected = "head: 1, Next_Node=3, Next_Node=2, Next_Node=5, Next_Node=None"
    assert actual == expected
コード例 #3
0
def test_kth_value_with_0():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    ll.insert(3)
    ll.insert(1)
    actual = ll.kth_value(0)
    expected = 2
    assert actual == expected
def test_ll_zip_shorter():
    ll_1 = LinkedList()
    ll_1.add('A')
    ll_1.add('B')
    ll_1.add('C')
    ll_1.add('D')

    ll_2 = LinkedList()
    ll_2.add('1')
    ll_2.add('2')
    ll_2.add('3')
    ll_2.add('4')
    ll_2.add('5')
    ll_2.add('6')

    head = ll_zip(ll_1, ll_2)
    assert head.value == 'A'
    assert ll_1.print() == 'A; 1; B; 2; C; 3; D; 4; 5; 6; '
def test_insert_three():
    mammals = LinkedList()
    mammals.insert('whale')
    mammals.insert('wolf')
    mammals.insert('ape')

    assert mammals.head.value == 'ape'
    assert mammals.head.nxt.value == 'wolf'
    assert mammals.head.nxt.nxt.value == 'whale'
コード例 #6
0
def test_llist_instance_insert():
    """testing when head was originally empty llist instance
    """
    finding_francis = LinkedList('goons')
    finding_francis.insert('meat-head')

    actual = finding_francis.head.value
    expected = 'meat-head'
    assert actual == expected
コード例 #7
0
def test_includes_method_false():
    finding_francis = LinkedList('goons')
    finding_francis.insert('meat-head')
    finding_francis.insert('brown-pants')
    finding_francis.insert('car-goon')

    actual = finding_francis.includes('ryan-reynalds')
    expected = False
    assert actual == expected
def test_k_is_greater_than_the_length_of_the_linked_list():
    newList = LinkedList()
    newList.insert(2)
    newList.insert(8)
    newList.insert(3)
    newList.insert(1)
    expected = "Exception"
    actual = newList.kthFromEnd(6)
    assert expected == actual
def test_k_and_the_length_of_the_list_are_the_same():
    newList = LinkedList()
    newList.insert(2)
    newList.insert(8)
    newList.insert(3)
    newList.insert(1)
    expected = '3'
    actual = newList.kthFromEnd(2)
    assert expected == actual
コード例 #10
0
def test_kth_method_middel():
  # 'Happy Path' where k is not at the end, but somewhere in the middle of the linked list
  lst_seven = LinkedList()
  lst_seven.insert(1)
  lst_seven.append(2)
  lst_seven.append(3)
  lst_seven.append(4)
  lst_seven.append(5)
  assert lst_seven.ll_kth_from_end(2) == 3
def test_can_successfully_insert_a_node_after_the_last_node_of_the_linked_list():
    newList = LinkedList()
    newList.insert("Three")
    newList.insert("Two")
    newList.insert("One")
    newList.insertAfter("Three", "Four")
    expected = [newList.headVal.nodeVal, newList.headVal.nextVal.nodeVal, newList.headVal.nextVal.nextVal.nodeVal, newList.headVal.nextVal.nextVal.nextVal.nodeVal]
    actual = ["One", "Two", "Three", "Four"]
    assert expected == actual
コード例 #12
0
def test_kth_method_same_as_length():
  # Where k and the length of the list are the same
  lst_seven = LinkedList()
  lst_seven.insert(1)
  lst_seven.append(2)
  lst_seven.append(3)
  lst_seven.append(4)
  lst_seven.append(5)
  assert lst_seven.ll_kth_from_end(5) == 1
コード例 #13
0
def test_insert_method():
  lst_one = LinkedList()
  lst_one.insert(1)
  lst_one.insert(2)
  lst_one.insert(3)

  assert lst_one.head.value == 3
  assert lst_one.head.next.value == 2
  assert lst_one.head.next.next.value == 1
コード例 #14
0
def test_insertBefore():
    ll = LinkedList()
    ll.append(1)
    ll.append(2)
    ll.append(3)
    ll.insertBefore(2, 20)
    assert ll.head.next.value == 20
    ll.insertBefore(20, 44)
    assert ll.head.next.value == 44
コード例 #15
0
def test_nth():
    node = Node(0)
    link = LinkedList(node)
    link.insert(4)
    link.append(10)
    link.kthFromEnd(1)
    actual = 0
    expected = 0
    assert actual == expected
def test_k_is_not_a_positive_integer():
    newList = LinkedList()
    newList.insert(2)
    newList.insert(8)
    newList.insert(3)
    newList.insert(1)
    expected = "Exception"
    actual = newList.kthFromEnd(-2)
    assert expected == actual
コード例 #17
0
def test_after():
    node = Node(0)
    link = LinkedList(node)
    link.insert(4)
    link.append(10)
    link.insert_after(10, 5)
    actual = str(link)
    expected = f'{{ 4 }} -> {{ 0 }} -> {{ 10 }} -> {{ 5 }} -> NONE'
    assert actual == expected
def test_where_k_is_not_at_the_end_but_somewhere_in_the_middle_of_the_linked_list():
    newList = LinkedList()
    newList.insert(2)
    newList.insert(8)
    newList.insert(3)
    newList.insert(1)
    expected = "3"
    actual = newList.kthFromEnd(2)
    assert expected == actual
コード例 #19
0
def test_next_of_origin_node():
    """tests next of the original head Node upon list instantiation
    """
    finding_francis = LinkedList('goons')
    finding_francis.insert('meat-head')
    finding_francis.insert('brown-pants')
    actual = finding_francis.__str__()
    expected = '{ brown-pants } -> { meat-head } -> { goons } -> None '
    assert actual == expected
def test_return_true_when_finding_a_value_within_the_linked_list_that_exists():
    newList = LinkedList()
    newList.insert("Three")
    newList.insert("Two")
    newList.insert("One") 
    newList.includes("Two")  
    expected = newList.includes("Three")
    actual = True
    assert expected == actual    
コード例 #21
0
def test_str_of_llist_class():
    finding_francis = LinkedList('goons')
    finding_francis.insert('meat-head')
    finding_francis.insert('brown-pants')
    finding_francis.insert('car-goon')

    actual = finding_francis.__str__()
    expected = '{ car-goon } -> { brown-pants } -> { meat-head } -> { goons } -> None '
    assert actual == expected
def test_return_false_when_searching_for_a_value_in_the_linked_list_that_does_not_exist():
    newList = LinkedList()
    newList.insert("Three")
    newList.insert("Two")
    newList.insert("One") 
    newList.includes("Two")  
    expected = newList.includes("Four")
    actual = False
    assert expected == actual  
def test_ll_reverse():
    ll = LinkedList()
    ll.add('A')
    ll.add('B')
    ll.add('C')
    ll.add('D')
    ll.add('E')
    ll_reverse(ll)
    assert ll.print() == 'E; D; C; B; A; '
def test_can_successfully_add_a_node_to_the_end_of_the_linked_list():
    newList = LinkedList()
    newList.insert("Three")
    newList.insert("Two")
    newList.insert("One")
    newList.append("Four")
    expected = [newList.headVal.nodeVal, newList.headVal.nextVal.nodeVal, newList.headVal.nextVal.nextVal.nodeVal, newList.headVal.nextVal.nextVal.nextVal.nodeVal]
    actual = ["One", "Two", "Three", "Four"]
    assert expected == actual
コード例 #25
0
def test_before_first():
    node = Node(0)
    link = LinkedList(node)
    link.insert_node(4)
    link.append(10)
    link.insert_node(5)
    actual = str(link)
    expected = f'{{ 5 }} -> {{ 4 }} -> {{ 0 }} -> {{ 10 }} -> NULL'
    assert actual == expected
コード例 #26
0
def test_zip_lists_same_length():
    node1 = Node(1)
    node2 = Node(2)
    node3 = Node(3)
    node4 = Node(4)
    node1.next = node2
    node2.next = node3
    node3.next = node4

    linked_list1 = LinkedList()
    linked_list1.head = node1
    linked_list2 = LinkedList()
    linked_list2.head = node1
    linked_list3 = LinkedList()
    linked_list3 = linked_list3.zip_lists(linked_list1, linked_list2)

    assert linked_list3.__str__(
    ) == "1 -> 1 -> 2 -> 2 -> 3 -> 3 -> 4 -> 4 -> None"
コード例 #27
0
def test_kth_value():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    ll.insert(3)
    ll.insert(1)
    actual = ll.kth_value(2)
    expected = 3
    assert actual == expected
コード例 #28
0
    def add(self, key, value):
        hash_index = self.hash(key)

        if not self.buckets[hash_index]:
            self.buckets[hash_index] = LinkedList()

        bucket = self.buckets[hash_index]

        bucket.insert([key, value])
コード例 #29
0
def test_kth_value_exception():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    ll.insert(3)
    ll.insert(1)
    actual = ll.kth_value(6)
    expected = "Exception"
    assert actual == expected
コード例 #30
0
def test_insert_multiple():
    L = LinkedList()
    L.insert("c")
    L.insert("b")
    L.insert("a")
    actual = str(L)
    print(actual)
    expected = " { a } -> { b } -> { c } -> NULL"
    assert actual == expected