Esempio n. 1
0
def test_merge_equal(predefined_ll, predefined_ll_other):
    """Merge equal sized lists."""
    merged = merge_lists(predefined_ll, predefined_ll_other)
    assert merged.val == 1
    assert merged._next.val == 10
    assert merged._next._next.val == 2
    assert merged._next._next._next.val == 9
    counter = 0
    while merged:
        merged = merged._next
        counter += 1
    assert counter == 20
Esempio n. 2
0
def test_merge_second_short(predefined_ll, predefined_ll_short):
    """Merge with a shorter second list."""
    merged = merge_lists(predefined_ll, predefined_ll_short)
    assert merged.val == 1
    assert merged._next.val == 11
    assert merged._next._next.val == 2
    assert merged._next._next._next.val == 12
    counter = 0
    while merged:
        merged = merged._next
        counter += 1
    assert counter == 14
Esempio n. 3
0
def test_merge_first_short(predefined_ll_short, predefined_ll):
    """Merge with a short first list."""
    merged = merge_lists(predefined_ll_short, predefined_ll)
    assert merged.val == 11
    assert merged._next.val == 1
    assert merged._next._next.val == 12
    assert merged._next._next._next.val == 2
    counter = 0
    while merged:
        merged = merged._next
        counter += 1
    assert counter == 14
Esempio n. 4
0
def test_ll_merge_one_first_one_short_list():
    linked_list_one = LinkedList()
    values_one = [1, 2, 3, 5, 7, 9]
    for el in values_one:
        linked_list_one.insert(el)

    linked_list_two = LinkedList()
    values_two = [4, 6, 8]
    for el in values_two:
        linked_list_two.insert(el)

    actual = merge_lists(linked_list_two, linked_list_one)
    assert '8 - 9 - 6 - 7 - 4 - 5 - 3 - 2 - 1 - None' == str(actual)
Esempio n. 5
0
def test_ll_merge_one_string_and_intiger():
    linked_list_one = LinkedList()
    values_one = [1, 2, 3, 5, 7, 9]
    for el in values_one:
        linked_list_one.insert(el)

    linked_list_two = LinkedList()
    values_two = [4, 6, 'f']
    for el in values_two:
        linked_list_two.insert(el)

    actual = merge_lists(linked_list_two, linked_list_one)
    assert 'f - 9 - 6 - 7 - 4 - 5 - 3 - 2 - 1 - None' == str(actual)
Esempio n. 6
0
def test_ll_merge_first_one_empty():
    linked_list_one = LinkedList()
    values_one = []
    for el in values_one:
        linked_list_one.insert(el)

    linked_list_two = LinkedList()
    values_two = [4, 6, 8]
    for el in values_two:
        linked_list_two.insert(el)

    actual = merge_lists(linked_list_one, linked_list_two)

    assert 'None' == str(actual)
Esempio n. 7
0
def test_ll_merge_second_one_empty():
    linked_list_one = LinkedList()
    values_one = [1, 2, 3, 5, 7, 9]
    for el in values_one:
        linked_list_one.insert(el)

    linked_list_two = LinkedList()
    values_two = []
    for el in values_two:
        linked_list_two.insert(el)

    actual = merge_lists(linked_list_one, linked_list_two)

    assert '9 - 7 - 5 - 3 - 2 - 1 - None' == str(actual)
Esempio n. 8
0
def test_ll_merge_first_one_long_list():
    linked_list_one = LinkedList()
    values_one = [1, 2, 3, 5, 7, 9]
    for el in values_one:
        linked_list_one.insert(el)

    linked_list_two = LinkedList()
    values_two = [4, 6, 8]
    for el in values_two:
        linked_list_two.insert(el)

    actual = merge_lists(linked_list_one, linked_list_two)

    assert '9 - 8 - 7 - 6 - 5 - 4 - 3 - 2 - 1 - None' == str(actual)
Esempio n. 9
0
def test_merge_list_small_first(small_ll, large_ll):
    merge_lists(small_ll, large_ll)
    assert large_ll._size == 12
Esempio n. 10
0
def test_merge_list_large_first(large_ll, small_ll):
    merge_lists(large_ll, small_ll)
    assert large_ll._size == 13
def test_ll_merge_basic_function(small_list, small_list_two):
    merged_lists = merge_lists(small_list, small_list_two)
    assert merged_lists.val == small_list.head.val
Esempio n. 12
0
def test_merge_none(predefined_ll):
    """Merge with empty lists."""
    empty = LL([])
    assert merge_lists(empty, predefined_ll).val == 1
    assert merge_lists(predefined_ll, empty).val == 1
    assert merge_lists(empty, empty) is None
Esempio n. 13
0
def test_merge_list_equal(second_small_ll, small_ll):
    merge_lists(second_small_ll, small_ll)
    assert small_ll.__len__() == 8
def text_ll_merge_equal_length_lists(create_linked_lists):
    assert print(merge_lists(list_1, list_2)) == '1, 2, 3, 4'
def text_ll_merge_equal_length_lists(create_linked_lists):
    assert print(merge_lists(list_2, list_1)) == 'A, 1, B, 2, C, 3, D, 4'
def text_ll_merge_equal_length_lists():
    create_linked_lists()
    assert print(merge_lists(list_1, list_2)) == '1, A, 2, B, 3, C, 4, D'
def test_ll_merge_ll_two_empty(small_list, empty_list):
    merged_lists = merge_lists(small_list, empty_list)
    assert merged_lists.val == small_list.head.val
def test_ll_merge_ll_one_empty(empty_list, small_list):
    merged_lists = merge_lists(empty_list, small_list)
    assert merged_lists.val == small_list.head.val