Example #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
Example #2
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
Example #3
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
Example #4
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')
Example #5
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
Example #6
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
Example #7
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
Example #8
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')
Example #9
0
def test_remove_not_found():
    dll = Dll()
    dll.append(600)
    dll.insert(700)
    with pytest.raises(LookupError):
        dll.remove(500)
Example #10
0
def test_remove_empty():
    dll = Dll()
    with pytest.raises(LookupError):
        dll.remove(500)