summaryrefslogtreecommitdiffstats
path: root/lang/python/python-lru-dict/test.sh
blob: 63c596fcc7c900c6bde3b1423360e811190e8e0b (plain)
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
30
31
#!/bin/sh

[ "$1" = python3-lru-dict ] || exit 0

python3 - << 'EOF'
from lru import LRU

cache = LRU(3)
cache["a"] = 1
cache["b"] = 2
cache["c"] = 3
assert len(cache) == 3

# Adding a 4th item evicts the least-recently-used entry ("a")
cache["d"] = 4
assert len(cache) == 3
assert "a" not in cache
assert "d" in cache

# Access "b" to make it recently used, then "c" becomes LRU
_ = cache["b"]
cache["e"] = 5
assert "b" in cache
assert "c" not in cache

# Test LRU capacity can be changed at runtime
cache.set_size(5)
assert cache.get_size() == 5

print("python3-lru-dict OK")
EOF