def main(): lru_obj = LRU(3) #tc1 assert lru_obj.get('a')==-1 #tc2 lru_obj.put('a',1) lru_obj.put('b',2) lru_obj.put('c',3) assert lru_obj.get('a')==1, 'Wrong Value' #tc3 assert lru_obj.get_cache()== {'a':1, 'b':2, 'c':3}, 'Cache is not updated properly' #tc4 lru_obj.put('d',4) #tc5 assert len(lru_obj.get_cache())==3, 'capacity crossed' #tc6 assert lru_obj.get('b')==-1, 'Least Recently Used is not being removed when capacity is crossed' print("All test cases passed!!")
def main(): l = [2, 9, 1, 7, 3, 5, 7, 6, 9, 2, 1] cache = LRU() for each in l: cache.put(each) print(cache.get_cache()) assert cache.get_cache() == [1, 2, 9, 6, 7, 5, 3]
def test_get_cache(self): obj = LRU('a',1) obj.put('a') obj.put('b') obj.put('c') obj.put('d') self.assertEqual(obj.get_cache(),['b','c','d'])
class LRUTest: def __init__(self): self.lru = LRU() def put(self, key): return self.lru.put(key) def get(self): return self.lru.get() def get_cache(self): return self.lru.get_cache()