def test_remove_4():
    l = DoubleLinkedList()
    l.append(5)
    l.remove(l.front)
    assert l.front is None
    assert l.end is None
    assert_contains(l, [])
def test_insert_after():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    l.append(9)
    l.insert_after(l.front, 13)
    assert l.front.next.value == 13
    assert_contains(l, [5, 13, 7, 9])
def test_linked_2():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    assert l.front.value == 5
    assert l.front.next.value == 7
    assert l.end.value == 7
    assert_contains(l, [5, 7])
def test_remove_6():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    l.remove(l.end)
    assert l.front.value == 5
    assert l.end is not None
    assert_contains(l, [5])
def test_remove_3():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    l.append(9)
    l.remove(l.front)
    assert l.front.value == 7
    assert l.end.value == 9
    assert_contains(l, [7, 9])
def test_remove_2():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    l.append(9)
    l.remove(l.end)
    assert l.front.value == 5
    assert l.end.value == 7
    assert_contains(l, [5, 7])
def test_remove():
    l = DoubleLinkedList()
    l.append(5)
    l.append(7)
    l.append(9)
    l.remove(l.front.next)
    assert l.front.value == 5
    assert l.front.next.value == 9
    assert_contains(l, [5, 9])
class LRUCache:
    class Node:
        def __init__(self, value, access_ref):
            self.value = value
            self.access_ref = access_ref

    def __init__(self, max_size):
        self.max_size = max_size
        self.cache = {}
        self.accesses = DoubleLinkedList()

    def set(self, key, value):
        self._evict()
        if key in self.cache:
            list_ref = self.cache[key].access_ref
            self.accesses.remove(list_ref)
            self.accesses._append(list_ref)
        else:
            list_ref = self.accesses.append(key)

        self.cache[key] = LRUCache.Node(value, list_ref)

    def get(self, key):
        if key not in self.cache:
            raise ValueError('{} not found in cache'.format(key))

        list_ref = self.cache[key].access_ref
        self.accesses.remove(list_ref)
        self.accesses._append(list_ref)
        return self.cache[key].value

    def _evict(self):
        if self.max_size == len(self.cache):
            node = self.accesses.front
            self.accesses.remove(node)
            del self.cache[node.value]
def test_insert_after_2():
    l = DoubleLinkedList()
    l.append(5)
    l.insert_after(l.front, 13)
    assert l.end.value == 13
    assert_contains(l, [5, 13])
def test_linked():
    l = DoubleLinkedList()
    l.append(5)
    assert l.front.value == 5
    assert l.end.value == 5