Esempio n. 1
0
def test_remove_with_one_node():
    """Test remove if only one node."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push('target')
    test_dll.remove('target')
    assert test_dll.head is None
Esempio n. 2
0
def test_append_empty():
    dll = Dll()
    dll.append(500)
    assert dll.head.prev is None
    assert dll.head.next_node is None
    assert dll.head.value == 500
    assert dll.head is dll.tail
Esempio n. 3
0
def test_append_two_nodes():
    """Test append function to add to tail."""
    from dll import Dll
    test_dll = Dll()
    test_dll.append(9)
    test_dll.append('goat')
    assert test_dll.tail.data == 'goat'
Esempio n. 4
0
def test_insert_empty():
    dll = Dll()
    dll.insert(500)
    assert dll.head.prev is None
    assert dll.head.next_node is None
    assert dll.head.value == 500
    assert dll.head is dll.tail
Esempio n. 5
0
def test_remove_head_of_list_with_multiple_nodes():
    """Test for remove method on list with multiple nodes."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push(11)
    test_dll.push('target')
    check = test_dll.head
    assert test_dll.remove('target') == check
Esempio n. 6
0
def test_append():
    dll = Dll()
    dll.append(500)
    first_node = dll.tail
    dll.append(600)
    assert dll.tail.prev is first_node
    assert dll.tail.next_node is None
    assert dll.tail.value == 600
    assert dll.head.next_node is dll.tail
Esempio n. 7
0
def test_insert():
    dll = Dll()
    dll.insert(500)
    first_node = dll.head
    dll.insert(600)
    assert dll.head.next_node is first_node
    assert dll.head.prev is None
    assert dll.head.value == 600
    assert dll.tail.prev is dll.head
Esempio n. 8
0
    def __init__(self):
        """Queue initiliazation.

        Composed of Doubly-Linked List attributes and methods.
        """
        self._dll = Dll()
        self._length = self._dll._length
        self.head = self._dll.head
        self.tail = self._dll.tail
Esempio n. 9
0
def test_remove_tail():
    dll = Dll()
    dll.insert(500)
    dll.insert(600)
    dll.insert(700)
    dll.remove(500)
    assert dll.tail.value == 600
    assert dll.tail.prev is dll.head
    assert dll.tail.next_node is None
Esempio n. 10
0
def test_remove_returns_node():
    """Test that correct node returned from search."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push(11)
    test_dll.push('target')
    check = test_dll.head
    test_dll.push(34)
    assert test_dll.remove('target') == check
Esempio n. 11
0
def test_pop():
    """Test pop function.

    Should remove first node and return value.
    """
    from dll import Dll
    test_dll = Dll()
    test_dll.push(1)
    assert test_dll.pop() == 1
Esempio n. 12
0
def test_remove_head():
    dll = Dll()
    dll.append(500)
    dll.append(600)
    dll.append(700)
    dll.remove(500)
    assert dll.head.value == 600
    assert dll.head.next_node is dll.tail
    assert dll.head.prev is None
Esempio n. 13
0
def test_shift():
    """Test shift function.

    Should remove last node and return value.
    """
    from dll import Dll
    test_dll = Dll()
    test_dll.append(8)
    assert test_dll.shift() == 8
Esempio n. 14
0
def test_dll_next_push_two():
    """Test list with two nodes.

    Second node should point back to head.
    """
    from dll import Dll
    test_dll = Dll()
    test_dll.push(1)
    test_dll.push(2)
    assert test_dll.head.next_node.prev.data == 2
Esempio n. 15
0
def test_dll_head_push_two():
    """Test list with two nodes.

    Head should point to next node.
    """
    from dll import Dll
    test_dll = Dll()
    test_dll.push(1)
    test_dll.push(2)
    assert test_dll.head.next_node.data == 1
Esempio n. 16
0
def test_remove_to_ensure_node_no_longer_exists():
    """Test remove method to ensure node is gone once remove is called."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push(11)
    test_dll.push('target')
    test_dll.push(34)
    test_dll.remove('target')
    with pytest.raises(ValueError):
        test_dll._linkedlist.search('target')
Esempio n. 17
0
def test_remove():
    dll = Dll()
    dll.insert(500)
    dll.insert(600)
    back = dll.head
    dll.insert(700)
    dll.insert(800)
    front = dll.head
    dll.insert(900)
    dll.remove(700)
    assert back.prev is front
    assert front.next_node is back
Esempio n. 18
0
def test_dll_attr():
    """Test if Dll object is created."""
    from dll import Dll
    test_dll = Dll()
    assert test_dll._length == 0
Esempio n. 19
0
def test_remove_with_empty_list():
    """Test to ensure error raised if remove called on empty list."""
    from dll import Dll
    test_dll = Dll()
    with pytest.raises(IndexError):
        test_dll.remove('a thing')
Esempio n. 20
0
 def __init__(self):
     """Initalize a Queue."""
     self._que = Dll()
Esempio n. 21
0
def dll():
    """Create a doubly linked list."""
    from dll import Dll
    dll = Dll()
    return dll
Esempio n. 22
0
def test_init_typeerror():
    """Can't initialize with parameter."""
    from dll import Dll
    with pytest.raises(TypeError):
        Dll(5)
Esempio n. 23
0
def test_dll_length_one():
    """Test pushing to an empty list."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push(1)
    assert test_dll._length == 1
Esempio n. 24
0
def test_append():
    """Test append function to add to tail."""
    from dll import Dll
    test_dll = Dll()
    test_dll.append(9)
    assert test_dll.tail.data == 9
Esempio n. 25
0
def test_shift_empty():
    dll = Dll()
    with pytest.raises(LookupError):
        dll.shift()
Esempio n. 26
0
def test_dll_push_one():
    """Test pushing to an empty list."""
    from dll import Dll
    test_dll = Dll()
    test_dll.push(1)
    assert test_dll.head.data == 1
Esempio n. 27
0
def test_remove_empty():
    dll = Dll()
    with pytest.raises(LookupError):
        dll.remove(500)
Esempio n. 28
0
def test_shift():
    dll = Dll()
    dll.append(500)
    dll.append(600)
    assert dll.shift() == 600
    assert dll.tail.next_node is None
Esempio n. 29
0
 def __init__(self):
     """Initialize new deque class object with a front and back."""
     self._dll = Dll()
     self.head = self._dll.head
     self.tail = self._dll.tail
     self._length = self._dll._length
Esempio n. 30
0
def test_remove_not_found():
    dll = Dll()
    dll.append(600)
    dll.insert(700)
    with pytest.raises(LookupError):
        dll.remove(500)