~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/tool/test/test_cache.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import autopath
 
2
from pypy.tool.cache import Cache 
 
3
 
 
4
class MyCache(Cache):
 
5
    counter = 0
 
6
    def _build(self, key):
 
7
        self.counter += 1
 
8
        return key*7
 
9
 
 
10
class TestCache: 
 
11
    def test_getorbuild(self):
 
12
        cache = MyCache()
 
13
        assert cache.getorbuild(1) == 7
 
14
        assert cache.counter == 1
 
15
        assert cache.getorbuild(1) == 7
 
16
        assert cache.counter == 1
 
17
        assert cache.getorbuild(3) == 21
 
18
        assert cache.counter == 2
 
19
        assert cache.getorbuild(1) == 7
 
20
        assert cache.counter == 2
 
21
        assert cache.getorbuild(3) == 21
 
22
        assert cache.counter == 2