Пример #1
0
    def test_pruning(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        # Contend 2 entries for the most-used slot to balloon the heap
        for i in xrange(100):
            d.get(i % 2)

        self.assertTrue(len(d.access_log) <= d.CLEANUP_FACTOR * d._maxsize)
Пример #2
0
    def test_pruning(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        # Contend 2 entries for the most-used slot to balloon the heap
        for i in xrange(100):
            d.get(i % 2)

        self.assertTrue(len(d.access_log) <= d.CLEANUP_FACTOR * d._maxsize)
Пример #3
0
    def test_expire(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        for i in xrange(5):
            d.get(0)

        # Add one more entry
        d[5] = '5'

        # Check state
        self.assertEqual(d.keys(), [0, 2, 3, 4, 5])
Пример #4
0
    def test_expire(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        for i in xrange(5):
            d.get(0)

        # Add one more entry
        d[5] = '5'

        # Check state
        self.assertEqual(d.keys(), [0, 2, 3, 4, 5])