forked from launchdarkly/python-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lru_cache.py
More file actions
29 lines (26 loc) · 1009 Bytes
/
Copy pathtest_lru_cache.py
File metadata and controls
29 lines (26 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from ldclient.impl.lru_cache import SimpleLRUCache
def test_retains_values_up_to_capacity():
lru = SimpleLRUCache(3)
assert lru.put("a", True) == False
assert lru.put("b", True) == False
assert lru.put("c", True) == False
assert lru.put("a", True) == True
assert lru.put("b", True) == True
assert lru.put("c", True) == True
def test_discards_oldest_value_on_overflow():
lru = SimpleLRUCache(2)
assert lru.put("a", True) == False
assert lru.put("b", True) == False
assert lru.put("c", True) == False
assert lru.get("a") is None
assert lru.get("b") == True
assert lru.get("c") == True
def test_value_becomes_new_on_replace():
lru = SimpleLRUCache(2)
assert lru.put("a", True) == False
assert lru.put("b", True) == False
assert lru.put("a", True) == True # b is now oldest
assert lru.put("c", True) == False # b is discarded as oldest
assert lru.get("a") is True
assert lru.get("b") is None
assert lru.get("c") is True