Example #1
0
def test_head():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    assert test.head.value == 3
Example #2
0
def test_includes():
    ll = LinkedList()
    ll.insert(3)
    ll.insert(2)
    ll.insert(1)
    ll.insert(0)
    assert ll.includes(3) == True
    assert ll.includes(5) == False
Example #3
0
def test_insert():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    expected = "{ 3 } -> { 2 } -> { 1 } -> { 0 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
Example #4
0
def test_includes():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    expected = True
    actual = test.includes(3)
    assert expected == actual
Example #5
0
def test_four():
    drinks = LinkedList()
    drinks.append("Coffee")
    drinks.append("Ice_Tea")
    drinks.append('Lemonade')
    drinks.includes("Lemonade")
    drinks.insert('Milk')
    expected = 'Milk -> Coffee -> Ice_Tea -> Lemonade -> None'
    actual = drinks.__str__()
    assert expected == actual
Example #6
0
def test_includes():
    ll = LinkedList()
    ll.insert("apples")
    ll.insert("bananas")
    ll.insert("cherries")
    assert ll.includes("bananas")
    assert ll.includes("oranges") == False
def test_to_string():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert cities.__str__() == "{ Chengdu } -> { Guangzhou } -> { Beijing } -> NULL"
def test_not_includes():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert not cities.includes("Shanghai")
Example #9
0
def repeated_word(string):
    '''
    using linked list this function will search for the first repeated word in your inputed string:
        inp ---> only string
        out >>> the repeated word from your input
    '''
    container = LinkedList()
    word = ''
    for i in range(len(string)):
        if container.includes(word):
            # print(container.toString())
            return word
        elif string[i] == ',' or string[i] == ' ' or string[
                i] == '-' or string[i] == '.':
            if word != '':
                container.insert(word)
                word = ''
            continue
        else:
            word += string[i].lower()
    # print(container.toString())
    return 'there is no repeated word in your input!'
Example #10
0
def test_insert_more():
    ll = LinkedList()
    ll.insert("apples")
    ll.insert("bananas")
    ll.insert("cherries")
    assert ll.head.value == "cherries"
    assert ll.head.next.value == "bananas"
    assert ll.head.next.next.value == "apples"
Example #11
0
def test_LinkedList_insertAfter():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertAfter(35, 1)
    assert test_LinkedList.__str__(
    ) == "{ 4 } -> { 35 } -> { 1 } -> { 5 } -> { 5555 } -> NULL"
Example #12
0
def test_LinkedList_insertBefore():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertBefore(35, 0)
    assert test_LinkedList.__str__(
    ) == "{ 4 } -> { 0 } -> { 35 } -> { 5 } -> { 5555 } -> NULL"
def test_insert():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert cities.head.val == "Chengdu"
    assert cities.head.next.val == "Guangzhou"
    assert cities.head.next.next.val == "Beijing"
Example #14
0
def test_LinkedList_kthFromEnd():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertAfter(35, 1)
    assert test_LinkedList.ll_kth_from_end(0) == 5555
    assert test_LinkedList.ll_kth_from_end(1) == 5
Example #15
0
def test_tostring():
    ll = LinkedList()
    assert ll.__str__() == "None"
    ll.insert("apples")
    assert ll.__str__() == "{apples}->None"
    ll.insert("bananas")
    assert ll.__str__() == "{bananas}->{apples}->None"
    ll.insert("cherries")
    assert ll.__str__() == "{cherries}->{bananas}->{apples}->None"
Example #16
0
def prep_ll():
    ll = LinkedList()
    ll.insert('Rania')
    ll.insert('Moh')
    return ll
def fixed_list():
    ll = LinkedList()
    ll.insert(9)
    ll.insert(4)
    ll.insert(3)
    return ll
Example #18
0
def test_insert():
    ll = LinkedList()
    ll.insert(5)
    assert ll.head.value == 5
    ll.insert(10)
    assert ll.head.value == 10
from data_structures_and_algorithms.data_structures.linked_list.linked_list import LinkedList
import pytest

linked_lii = LinkedList()
linked_lii.insert(3)
linked_lii.insert(6)
linked_lii.insert(9)


def test_instance():
    assert isinstance(linked_lii, LinkedList)


def test_insert():
    data = ''
    linked_list = linked_lii.head
    while linked_list:
        data += f'{linked_list.data},'
        linked_list = linked_list.next
    assert data == '3,6,9,'


def test_head():
    assert linked_lii.head.data == 3


def test_head_next():
    assert linked_lii.head.next.next.data == 9


def test_finding_notExist_value():
Example #20
0
def test_LinkedList_insert():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(0)
    assert test_LinkedList.head.value == 0
Example #21
0
from data_structures_and_algorithms.data_structures.linked_list.linked_list import (
    LinkedList, )
import pytest

ll = LinkedList()
ll.insert(3)
ll.insert(6)
ll.insert(9)


def test_instance():
    assert isinstance(ll, LinkedList)


def test_insert():
    result = ''
    linked_list = ll.head
    while linked_list:
        result += f'{linked_list.value},'
        linked_list = linked_list.next
    assert result == '3,6,9,'


def test_head():
    assert ll.head.value == 3


def test_finding_notExist_value():
    assert ll.includes(5) == False

Example #22
0
def test_LinkedList_insert_second_Test():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(0)
    assert test_LinkedList.head.value == 0
    test_LinkedList.insert(1)
    assert test_LinkedList.head.next.value == 0
Example #23
0
def test_LinkedList_includes():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(0)
    test_LinkedList.insert(1)
    assert test_LinkedList.includes(1) == True
    assert test_LinkedList.includes(100) == False
Example #24
0
def test_insert_two():
    ll = LinkedList()
    ll.insert("apples")
    ll.insert("bananas")
    assert ll.head.value == "bananas"
    assert ll.head.next.value == "apples"
Example #25
0
def test_insert_one():
    ll = LinkedList()
    ll.insert("apples")
    assert ll.head.value == "apples"
    assert ll.head.next == None
def test_kth_from_end_when_linked_list_length_is_one():
    tt = LinkedList()
    tt.insert(5)
    assert tt.kth_from_end(0) == 5
Example #27
0
def test__str__():
    ll = LinkedList()
    ll.insert('c')
    ll.insert('b')
    ll.insert('a')
    assert ll.__str__() == "{ a } -> { b } -> { c } -> NULL"
def prep_tt():
    tt = LinkedList()
    tt.insert(5)
    tt.insert(7)

    return tt
Example #29
0
def test__str__():
    test_LinkedList = LinkedList()
    test_LinkedList.insert('9')
    test_LinkedList.insert('1')
    test_LinkedList.insert('-')
    test_LinkedList.insert('D')
    test_LinkedList.insert('I')
    test_LinkedList.insert('V')
    test_LinkedList.insert('O')
    test_LinkedList.insert('C')
    test_LinkedList.insert('_')
    test_LinkedList.insert('0')
    test_LinkedList.insert('2')
    test_LinkedList.insert('0')
    test_LinkedList.insert('2')
    assert test_LinkedList.__str__(
    ) == "{ 2 } -> { 0 } -> { 2 } -> { 0 } -> { _ } -> { C } -> { O } -> { V } -> { I } -> { D } -> { - } -> { 1 } -> { 9 } -> NULL"