from gzz.util import CachingMap def testNumber(): """Test that a cachingmap will start removing elements when it hits the given size. """ c = CachingMap(4) c.put("A", "X") failUnlessEqual(c.get("A"), "X") failUnlessEqual(c.size(), 1) c.put("A", "Y") failUnlessEqual(c.size(), 1) c.put("B", "X") failUnlessEqual(c.size(), 2) c.put("C", "X") failUnlessEqual(c.size(), 3) c.put("D", "X") failUnlessEqual(c.size(), 4) # Now, run against the limit c.put("FOO", "X") failUnlessEqual(c.size(), 4) def testNegSize(): """Test that you can't create a cachingmap with a negative size """ try: c = CachingMap(-1) except: return 0 failIf(1) def testZeroSize(): """Test that a zero-size cachingmap works right, i.e. that put() is a noop. """ c = CachingMap(0) c.put("A","X") failUnlessEqual(c.get("A"), None)