def test_memoize():
"""Test Caching with no Time-To-Live (TTL)."""
global x
for fn in memoize_fns:
x = 0
assert_eq(4, fn(1))
assert_eq(1, x)
assert_eq(8, fn(2, 4))
assert_eq(2, x)
# should not result in another call
assert_eq(8, fn(2, z=4))
assert_eq(2, x)
assert_eq(8, fn(y=2, z=4))
assert_eq(2, x)
fn.clear_cache()
assert_eq(4, fn(1))
assert_eq(3, x)
评论列表
文章目录