summaryrefslogtreecommitdiff
path: root/test/test_lru.py
blob: f54bd1580f5b2de6761b61d5f92c75bd0c3e8ad9 (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
32
33
34
35
36
37
38
39
from mako.util import LRUCache


class item:
    def __init__(self, id_):
        self.id = id_

    def __str__(self):
        return "item id %d" % self.id


class LRUTest:
    def testlru(self):
        l = LRUCache(10, threshold=0.2)

        for id_ in range(1, 20):
            l[id_] = item(id_)

        # first couple of items should be gone
        assert 1 not in l
        assert 2 not in l

        # next batch over the threshold of 10 should be present
        for id_ in range(11, 20):
            assert id_ in l

        l[12]
        l[15]
        l[23] = item(23)
        l[24] = item(24)
        l[25] = item(25)
        l[26] = item(26)
        l[27] = item(27)

        assert 11 not in l
        assert 13 not in l

        for id_ in (25, 24, 23, 14, 12, 19, 18, 17, 16, 15):
            assert id_ in l