def test_append_via_shift():
    """Tests append method for doublelinked list; using len"""
    adding_to = DoubleLinkList(())
    for i in xrange(40):
        adding_to.append(i)

    assert adding_to.shift() == 39
def test_insert_via_shift():
    """Tests insert function for doublelinked list; using shift"""
    adding_to = DoubleLinkList(())
    for i in xrange(40):
        adding_to.insert(i)

    assert adding_to.shift() == 0
def test_insert_via_len():
    """Tests insert function for doublelinked list; using len"""
    adding_to = DoubleLinkList(())
    for i in xrange(40):
        adding_to.insert(i)

    assert len(adding_to) == 40
    assert adding_to.pop() == 39
def test_remove_5():
    """Fill a DoubleLinkList with (1,2,3), check removal of 5;
    should result in ValueError"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)
    with pytest.raises(ValueError):
        adding_to.remove(5)
示例#5
0
class Stack():
    def __init__(self):
        self.__list = DoubleLinkList()

    def push_item(self, value):
        return self.__list.add(value)

    def pop_item(self):
        return self.__list.r

    def __str__(self):
        return self.__list.__str__()
def test_pop_4():
    """Fill a DoubleLinkList with (1,2,3), check fourth pop"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)

    adding_to.pop()  # First action covered by test_pop_1
    adding_to.pop()  # Second action covered by test_pop_2
    adding_to.pop()
    with pytest.raises(IndexError):
        adding_to.pop()
def test_remove_2():
    """Fill a DoubleLinkList with (1,2,3), check removal of 3"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)

    adding_to.remove(2)
    assert adding_to.pop() == 1
    assert adding_to.shift() == 0
def test_shift_2():
    """Fill a DoubleLinkList with (1,2,3), check second pop"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)

    adding_to.shift()  # First action covered by test_pop_1
    assert adding_to.shift() == 1
def test_pop_3():
    """Fill a DoubleLinkList with (1,2,3), check third pop"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)

    adding_to.pop()  # First action covered by test_pop_1
    adding_to.pop()  # Second action covered by test_pop_2
    assert adding_to.pop() == 0
from double_link_list import DoubleLinkList
import pytest


@pytest.mark.parametrize(
    "initial_list, ll, method, params",
    [
        ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__len__", ()),
        ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "pop", ()),
        ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "insert", (0, 2)),
        ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "insert", (1, 2)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__delitem__", (0,)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__delitem__", (1,)),
        ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "reverse", ()),
        # ([3], DoubleLinkList.from_list([3]), "reverse", ()),
        # ([], DoubleLinkList.from_list([]), "reverse", ()),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "clear", ()),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "extend", ([1, 2, 3],)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "sort", ()),
        # ([5, 3, 7], DoubleLinkList.from_list([5, 3, 7]), "sort", ()),
        # ([3, 7, 3], DoubleLinkList.from_list([3, 7, 3]), "sort", ()),
        # ([7, 3], DoubleLinkList.from_list([7, 3]), "sort", ()),
        # ([3], DoubleLinkList.from_list([3]), "sort", ()),
        # ([], DoubleLinkList.from_list([]), "sort", ()),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__setitem__", (1, 2)),
        # ([], DoubleLinkList.from_list([]), "__setitem__", (0, 2)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__setitem__", (-1, 2)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "__setitem__", (100, 2)),
        #
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "count", (3,)),
        # ([3, 5, 7], DoubleLinkList.from_list([3, 5, 7]), "count", (1,)),
示例#11
0
 def __init__(self):
     self.__list = DoubleLinkList()
def test_shift_1():
    """Fill a DoubleLinkList with (1,2,3), check first pop"""
    adding_to = DoubleLinkList(())
    for i in xrange(3):
        adding_to.insert(i)
    assert adding_to.shift() == 0
示例#13
0
from double_link_list import DoubleLinkList

l1 = DoubleLinkList()
print(l1.is_empty())
print(l1.length())

l1.append(1)
print(l1.is_empty())
print(l1.length())
l1.append(2)
l1.add(8)
l1.append(3)
l1.append(4)
l1.append(5)
l1.append(6)
l1.insert(-1, 9)
l1.travel()
l1.insert(2, 100)
l1.travel()
l1.insert(10, 200)
l1.travel()
print(l1.search(100))
l1.remove(9)
l1.travel()
l1.remove(200)
l1.travel()