Exemplo n.º 1
0
def test_solution():
    cache = LRUCache(2)
    cache.put(1, 1)
    cache.put(2, 2)
    assert cache.get(1) == 1
    cache.put(3, 3)
    assert cache.get(2) == -1
    cache.put(4, 4)
    assert cache.get(1) == -1
    assert cache.get(3) == 3
    assert cache.get(4) == 4
Exemplo n.º 2
0
def main():
    test = LRUCache(3)
    test.put(1, "one")
    test.put(2, "two")
    test.put(3, "three")
    assert test.cache == {1: "one", 2: "two", 3: "three"}
    test.put(3, "four")
    assert test.cache == {1: "one", 2: "two", 3: "four"}
    test.put(4, "five")
    test.put(5, "six")
    assert test.cache == {3: "four", 4: "five", 5: "six"}
    print("Yayy! All the assert statements are passed.")
Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from solution import LRUCache
from solution import DLinkNode

lru = LRUCache(3)
lru.set(1, 1)
lru.set(2, 2)
lru.set(3, 3)
lru.set(4, 4)
print(lru.get(4))
print(lru.get(3))
print(lru.get(2))
print(lru.get(1))
lru.set(5, 5)
print(lru.get(1))
print(lru.get(2))
print(lru.get(3))
print(lru.get(4))
print(lru.get(5))
Exemplo n.º 4
0
 def setUp(self):
     self.cache = LRUCache(2)
Exemplo n.º 5
0
 def setUp(self):
     """Set up our SUT for testing."""
     self.sut = LRUCache(capacity=2)