def test_can_return_all_elements_in_list():
    x = LinkedList()
    x.insert("c")
    x.insert("b")
    x.insert("a")
    actual = x.__str__()
    expected = "{ a } -> { b } -> { c } -> NULL"
    assert actual == expected
def test_insert_multiple_node():
    x = LinkedList()
    x.insert("a")
    x.insert("c")
    x.insert("e")
    y = LinkedList()
    y.insert("b")
    y.insert("d")
    y.insert("f")
    z = zip_lists(x, y)
    actual = z.contains()
    expected = ["f", "e", "d", "c", "b", "a"]
    assert actual == expected
def test_where_k_is_not_a_positive_integer():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.kth_from_end(-3)
    expected = "you must enter a positive value"
    assert actual == expected
def test_where_k_and_the_length_of_the_list_are_the_same():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.kth_from_end(5)
    expected = "k is greater than length of linked list"
    assert actual == expected
def test_kth_from_end_returns_correct_node_value():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.kth_from_end(2)
    expected = "c"
    assert actual == expected
def test_return_false_if_value_in_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.includes("z")
    expected = False
    assert actual == expected
def test_head_node_fist_in_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.head.val
    expected = "e"
    assert actual == expected
def test_insert_multiple_node():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    actual = x.contains()
    expected = ["e", "d", "c", "b", "a"]
    assert actual == expected
Example #9
0
def test_can_successfully_add_a_node_to_the_end_of_the_linked_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    x.append("g")
    actual = x.contains()
    expected = ["e","d","c","b","a","g"]
    assert actual == expected
Example #10
0
def test_can_successfully_insert_a_node_after_the_last_node_of_the_linked_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    x.insert_after("a", "test")
    actual = x.contains()
    expected = ["e","d","c","b","a","test"]
    assert actual == expected
Example #11
0
def test_can_successfully_insert_a_node_before_the_first_node_of_a_linked_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    x.insert_before("e", "test")
    actual = x.contains()
    expected = ["test","e","d","c","b","a"]
    assert actual == expected
Example #12
0
def test_can_successfully_add_multiple_nodes_to_the_end_of_a_linked_list():
    x = LinkedList()
    x.insert("a")
    x.insert("b")
    x.insert("c")
    x.insert("d")
    x.insert("e")
    x.append("test one")
    x.append("test two")
    actual = x.contains()
    expected = ["e","d","c","b","a", "test one", "test two"]
    assert actual == expected
def test_where_the_linked_list_is_of_a_size_1():
    x = LinkedList()
    x.insert("a")
    actual = x.kth_from_end(0)
    expected = "a"
    assert actual == expected
def test_insert_single_node():
    x = LinkedList()
    x.insert("a")
    actual = x.head.val
    expected = "a"
    assert actual == expected
def test_dif_length_lists():
    x = LinkedList()
    x.insert("4")
    x.insert("3")
    x.insert("2")
    x.insert("1")
    x.insert("a")
    x.insert("c")
    x.insert("e")
    y = LinkedList()
    y.insert("b")
    y.insert("d")
    y.insert("f")
    z = zip_lists(x, y)
    actual = z.contains()
    expected = ["f", "e", "d", "c", "b", "a", "1", "2", "3", "4"]
    assert actual == expected