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
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.")
#!/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))
def setUp(self): self.cache = LRUCache(2)
def setUp(self): """Set up our SUT for testing.""" self.sut = LRUCache(capacity=2)