Exemplo n.º 1
0
def test_put_1():
    """Put one item => size == 1"""
    lru = LRUCache(1)

    lru.put(1, 'a')

    assert lru.currentsize == 1
Exemplo n.º 2
0
def test_put_6():
    """Put same item over and over, max size 10 => size == 1"""
    lru = LRUCache(10)

    for i in range(0, 10):
        lru.put(0, str(0))

    assert lru.currentsize == 1
Exemplo n.º 3
0
def test_put_5():
    """Put 10 item, max size 10 => size == 10"""
    lru = LRUCache(10)

    for i in range(0, 10):
        lru.put(i, str(i))

    assert lru.currentsize == 10
Exemplo n.º 4
0
def test_put_3():
    """Put one item, then delete, max size 1 => size == 0"""
    lru = LRUCache(1)

    lru.put(1, 'a')
    lru.delete(1)

    assert lru.currentsize == 0
Exemplo n.º 5
0
def test_put_2():
    """Put two different items, max size 1 => size == 1"""
    lru = LRUCache(1)

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

    assert lru.currentsize == 1
Exemplo n.º 6
0
def test_get():
    """Get an item => size remains the same"""
    lru = LRUCache(10)

    for i in range(0, 10):
        lru.put(i, str(i))

    val = lru.get(1)

    assert lru.currentsize == 10
Exemplo n.º 7
0
def test_reset():
    """Put some items in cache, then clear it => size == 0"""
    lru = LRUCache(10)

    for i in range(0, 10):
        lru.put(i, str(i))

    lru.reset()

    assert lru.currentsize == 0
Exemplo n.º 8
0
def test_delete():
    """Add 10 items then delete 3 ==> size == 7"""
    lru = LRUCache(10)

    for i in range(0, 10):
        lru.put(i, str(i))

    lru.delete(0)
    lru.delete(3)
    lru.delete(7)

    assert lru.currentsize == 7
Exemplo n.º 9
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]
Exemplo n.º 10
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]
Exemplo n.º 11
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]
Exemplo n.º 12
0
def test_put_4():
    """Put 5 item, max size 10 => size == 5"""
    lru = LRUCache(10)

    lru.put(1, 'a')
    lru.put(2, 'b')
    lru.put(3, 'c')
    lru.put(4, 'd')
    lru.put(5, 'e')

    assert lru.currentsize == 5
Exemplo n.º 13
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("-")