コード例 #1
0
def test_delete_4():
    """
    Tests deletting a key that doesn't exist results in a no-op
    """
    lru = LRUCache(5)

    lru.put(1, 1)
    lru.put(2, 2)
    lru.put(3, 3)

    lru.delete(10)

    assert lru._printForward() == [1, 2, 3]
コード例 #2
0
def test_delete_1():
    """
    Tests that an item can be removed from the cache
    Delete from middle
    """
    lru = LRUCache(5)

    lru.put(1, 1)
    lru.put(2, 2)
    lru.put(3, 3)

    lru.delete(2)

    assert lru._printForward() == [1, 3]
コード例 #3
0
def test_delete_2():
    """
    Tests that an item can be removed from the cache
    Delete from head
    """
    lru = LRUCache(5)

    lru.put(1, 1)
    lru.put(2, 2)
    lru.put(3, 3)

    lru.delete(1)

    assert lru._printForward() == [2, 3]
コード例 #4
0
from lru_cache.LRUCache import LRUCache

"""
This file was used for debugging the LRUCache
"""

if __name__ == '__main__':
    
    lru = LRUCache(3)
    
    for i in range(0,3):
        lru.put(i, str(i)) 
    
    print(lru._printForward())

    lru.reset()

    lru.put(0, 'a')
    lru.put(1, 'b')
    lru.put(2, 'c')

    print(lru._printForward())

    lru.get(1)
    #lru.reset()

    lru.put(1, 'a')
    
    print(lru._printForward())
    print("-")