コード例 #1
0
ファイル: lru_cache_tests.py プロジェクト: zhengr/pydatalab
    def test_cache_lookup(self):
        cache = LRUCache(4)
        for x in ['a', 'b', 'c', 'd']:
            cache[x] = x

        for x in ['a', 'b', 'c', 'd']:
            self.assertEqual(x, cache[x])
コード例 #2
0
ファイル: lru_cache_tests.py プロジェクト: zhengr/pydatalab
    def test_cache_overflow(self):
        cache = LRUCache(3)
        for x in ['a', 'b', 'c', 'd']:
            cache[x] = x

        for x in ['b', 'c', 'd']:
            self.assertEqual(x, cache[x])

        with self.assertRaises(KeyError):
            _ = cache['a']

        _ = cache['b']
        _ = cache['d']
        # 'c' should be LRU now
        cache['e'] = 'e'

        with self.assertRaises(KeyError):
            _ = cache['c']

        for x in ['b', 'd', 'e']:
            self.assertEqual(x, cache[x])
コード例 #3
0
ファイル: lru_cache_tests.py プロジェクト: zhengr/pydatalab
 def test_cache_no_entry(self):
     cache = LRUCache(3)
     with self.assertRaises(KeyError):
         _ = cache['a']