From 578c0ac4cbc434d89554312f28153ae109fd1d96 Mon Sep 17 00:00:00 2001 From: Jay Hutchinson Date: Mon, 25 Jul 2011 13:18:45 -0500 Subject: Added code to test resizing a cache. --- test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test.py b/test.py index 258bf3f..c3346e3 100644 --- a/test.py +++ b/test.py @@ -59,6 +59,12 @@ class simplelrucache: raise KeyError + def resize(self, x=None): + assert x > 0 + self.size = x + if x < len(self.cache): + del self.cache[:len(self.cache) - x] + def test(a, b, c, d, verify): @@ -112,7 +118,22 @@ def testcache(): a = lrucache(128) b = simplelrucache(128) + verify(a, b) + test(a, b, a, b, verify) + + a.size(71) + b.resize(71) + verify(a, b) + test(a, b, a, b, verify) + + a.size(341) + b.resize(341) + verify(a, b) + test(a, b, a, b, verify) + a.size(127) + b.resize(127) + verify(a, b) test(a, b, a, b, verify) -- cgit v1.2.1