Skip to content

Commit fc53f3b

Browse files
Added more tests in doctests and fixed return types fixes [TheAlgorithms#4628]
1 parent e5b6af1 commit fc53f3b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: other/lru_cache_pythonic.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class LRUCache(dict):
1010
Initialize an LRU Cache with given capacity.
1111
capacity : int -> the capacity of the LRU Cache
1212
'''
13-
def __init__(self, capacity : int):
13+
def __init__(self, capacity : int)->None:
1414
self.remaining:int = capacity
1515

1616
'''
@@ -36,8 +36,15 @@ def get(self, key:Hashable)->Any:
3636
This method puts the value associated with the key provided inside of the LRU cache.
3737
key : Hashable -> a hashable object that is mapped to a value inside of the LRU cache.
3838
value: Any -> any object that is to be associated with the key inside of the LRU cache.
39+
>>> cache = LRUCache(2)
40+
>>> cache.put(3,3)
41+
>>> cache
42+
{3:3}
43+
>>> cache.put(2,2)
44+
>>> cache
45+
{3:3, 2:2}
3946
'''
40-
def put(self, key:Hashable, value:Any):
47+
def put(self, key:Hashable, value:Any)->None:
4148
# To pop the last value inside of the LRU cache
4249
if key in self:
4350
self.pop(key)
@@ -49,7 +56,7 @@ def put(self, key:Hashable, value:Any):
4956
else: self.pop(next(iter(self)))
5057
self[key] = value
5158

52-
def main():
59+
def main()->None:
5360
'''Example test case with LRU_Cache of size 2'''
5461
cache = LRUCache(2) # Creates an LRU cache with size 2
5562
cache.put(1,1) # cache = {1:1}

0 commit comments

Comments
 (0)