Example #1
0
def test_first_is_bigger():
    my_list = LinkedList()
    my_list.insert(4)
    my_list.insert(3)
    my_list.insert(2)
    my_list.insert(1)
    other_list = LinkedList()
    other_list.insert(6)
    other_list.insert(5)
    merge_list(my_list, other_list)
    assert my_list.to_string() == '  1 5 2 6 3 4'
Example #2
0
def test_merge_same_size():
    my_list = LinkedList()
    my_list.insert(3)
    my_list.insert(2)
    my_list.insert(1)
    other_list = LinkedList()
    other_list.insert(6)
    other_list.insert(5)
    other_list.insert(4)
    merge_list(my_list, other_list)
    assert my_list.to_string() == '  1 4 2 5 3 6'
Example #3
0
def test_second_is_bigger():
    my_list = LinkedList()
    my_list.insert(2)
    my_list.insert(1)
    other_list = LinkedList()
    my_list.insert(4)
    my_list.insert(3)
    other_list.insert(6)
    other_list.insert(5)
    merge_list(my_list, other_list)
    assert my_list.to_string() == '  3 5 4 6 1 2'
Example #4
0
def test_list_2nd_empty():
    l_list2 = LinkedList()
    l_list1 = create_list(['d', 'c', 'b', 'a'])
    ref_to_head = merge_list(l_list1, l_list2)
    assert ref_to_head.value == "a"
    assert l_list1.__str__() == 'a, b, c, d'
Example #5
0
def test_2_empty():
    list_1 = LinkedList(['a', 'b'])
    list_2 = LinkedList()
    list_3 = merge_list(list_1, list_2)
    assert list_3.__str__() == 'a : b : None'
Example #6
0
def test_1_empty():
    list_1 = LinkedList()
    list_2 = LinkedList(['b', 'c'])
    list_3 = merge_list(list_1, list_2)
    assert list_3.__str__() == 'b : c : None'
Example #7
0
def test_empty_lists():
    list_1 = LinkedList()
    list_2 = LinkedList()
    with pytest.raises(Exception):
        merge_list(list_1, list_2)
Example #8
0
def test_2_list_1_element():
    list_1 = LinkedList([1, 3])
    list_2 = LinkedList([2])
    list_3 = merge_list(list_1, list_2)
    assert list_3.__str__() == '1 : 2 : 3 : None'
Example #9
0
def test_1_list_1_element():
    list_1 = LinkedList([1])
    list_2 = LinkedList(['b', 'c'])
    list_3 = merge_list(list_1, list_2)
    assert list_3.__str__() == '1 : b : c : None'
Example #10
0
def test_2_shorter():
    list_1 = LinkedList(['1', '3', '2'])
    list_2 = LinkedList(['5', '9'])
    list_3 = merge_list(list_1, list_2)
    assert list_3.__str__() == '1 : 5 : 3 : 9 : 2 : None'
Example #11
0
def test_merge_one(ll_one):
    empty_list = LinkedList()
    empty_list.insert('b')
    new_ll = merge_list(ll_one, empty_list)
    assert new_ll.get_length() == 'a -> b -> '
Example #12
0
def test_1slist_shorter():
    l_list1 = create_list(['d', 'c', 'b', 'a'])
    l_list2 = create_list(['h', 'g', 'f', 'e', 'z'])
    ref_to_head = merge_list(l_list1, l_list2)
    assert ref_to_head.value == "a"
    assert l_list1.__str__() == 'a, z, b, e, c, f, d, g, h'
Example #13
0
def test_lists_empty():
    l_list1 = LinkedList()
    l_list2 = LinkedList()
    with pytest.raises(Exception):
        merge_list(l_list1, l_list2)
Example #14
0
def test_lists_equal():
    l_list1 = create_list(['d', 'c', 'b', 'a'])
    l_list2 = create_list(['h', 'g', 'f', 'e'])
    ref_to_head = merge_list(l_list1, l_list2)
    assert ref_to_head.value == "a"
    assert l_list1.__str__() == 'a, e, b, f, c, g, d, h'
Example #15
0
def test_1slist_longer():
    l_list1 = create_list(['d', 'c', 'b', 'a', 'z'])
    l_list2 = create_list(['h', 'g', 'f', 'e'])
    ref_to_head = merge_list(l_list1, l_list2)
    assert ref_to_head.value == "z"
    assert l_list1.__str__() == 'z, e, a, f, b, g, c, h, d'
Example #16
0
def test_merge_different_length(ll_three, ll_five):
    new_ll = merge_list(ll_five, ll_three)
    assert new_ll.get_length() == 'True -> 3 -> c -> a -> 8 -> 2 -> a -> 9 -> '
Example #17
0
def test_merge_many(ll_six, ll_eight):
    new_ll = merge_list(ll_six, ll_eight)
    assert new_ll.get_length(
    ) == '6 -> 1 -> False -> 7 -> p -> w -> 8 -> True -> h -> c -> 9 -> 2 -> z -> 4 -> '
Example #18
0
def test_list_2ndlist_1element():
    l_list1 = create_list(['d', 'c', 'b', 'a'])
    l_list2 = create_list([1])
    ref_to_head = merge_list(l_list1, l_list2)
    assert ref_to_head.value == 'a'
    assert l_list1.__str__() == 'a, 1, b, c, d'
Example #19
0
def test_merge_none(ll_none):
    new_ll = merge_list(ll_none, ll_none)
    assert new_ll.get_length() == ''