summaryrefslogtreecommitdiff
path: root/test/test_lru.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-01-19 10:33:00 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-01-19 10:33:00 -0500
commit6779081b32cfb237062da8bc623a27d47301ce4c (patch)
treefc3372c916cfc9efc61cccffde74528772532b37 /test/test_lru.py
parent76e622b46ef71eddfbcd1232ee08b4e55c88c363 (diff)
downloadmako-6779081b32cfb237062da8bc623a27d47301ce4c.tar.gz
- now that trailing whitespace comes up in red, need to get rid of it
Diffstat (limited to 'test/test_lru.py')
-rw-r--r--test/test_lru.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/test/test_lru.py b/test/test_lru.py
index e2b5c15..ade48a3 100644
--- a/test/test_lru.py
+++ b/test/test_lru.py
@@ -13,16 +13,16 @@ class item:
class LRUTest(unittest.TestCase):
- def testlru(self):
+ def testlru(self):
l = LRUCache(10, threshold=.2)
-
+
for id in range(1,20):
l[id] = item(id)
-
+
# first couple of items should be gone
- self.assert_(not l.has_key(1))
+ self.assert_(not l.has_key(1))
self.assert_(not l.has_key(2))
-
+
# next batch over the threshold of 10 should be present
for id in range(11,20):
self.assert_(l.has_key(id))
@@ -37,9 +37,9 @@ class LRUTest(unittest.TestCase):
self.assert_(not l.has_key(11))
self.assert_(not l.has_key(13))
-
+
for id in (25, 24, 23, 14, 12, 19, 18, 17, 16, 15):
- self.assert_(l.has_key(id))
+ self.assert_(l.has_key(id))
def _disabled_test_threaded(self):
size = 100
@@ -47,13 +47,13 @@ class LRUTest(unittest.TestCase):
all_elems = 2000
hot_zone = range(30,40)
cache = LRUCache(size, threshold)
-
+
# element to store
class Element(object):
def __init__(self, id):
self.id = id
self.regets = 0
-
+
# return an element. we will favor ids in the relatively small
# "hot zone" 25% of the time.
def get_elem():
@@ -61,7 +61,7 @@ class LRUTest(unittest.TestCase):
return hot_zone[random.randint(0, len(hot_zone) - 1)]
else:
return random.randint(1, all_elems)
-
+
total = [0]
# request thread.
def request_elem():
@@ -74,19 +74,19 @@ class LRUTest(unittest.TestCase):
except KeyError:
e = Element(id)
cache[id] = e
-
+
time.sleep(random.random() / 1000)
for x in range(0,20):
thread.start_new_thread(request_elem, ())
-
+
# assert size doesn't grow unbounded, doesnt shrink well below size
for x in range(0,5):
time.sleep(1)
print "size:", len(cache)
assert len(cache) < size + size * threshold * 2
assert len(cache) > size - (size * .1)
-
+
# computs the average number of times a range of elements were "reused",
# i.e. without being removed from the cache.
def average_regets_in_range(start, end):
@@ -99,13 +99,13 @@ class LRUTest(unittest.TestCase):
hotzone_avg = average_regets_in_range(30, 40)
control_avg = average_regets_in_range(450,760)
total_avg = average_regets_in_range(0, 2000)
-
+
# hotzone should be way above the others
print "total fetches", total[0], "hotzone", \
hotzone_avg, "control", \
control_avg, "total", total_avg
-
+
assert hotzone_avg > total_avg * 5 > control_avg * 5
-
-
+
+