The function decoarted should be called once for the same argument. Check that.
def test_memo__function_should_be_called_once_for_same_arg(self):
@memo
def f(arg):
f.call_count += 1
return arg
f.call_count = 0
self.assertEqual(f(1), 1)
self.assertEqual(f(1), 1)
self.assertEqual(f.call_count, 1)
self.assertEqual(f(2), 2)
self.assertEqual(f(2), 2)
self.assertEqual(f(2), 2)
self.assertEqual(f.call_count, 2)
BTW, In the cached_fib
function, it should call cache_fib
, not fib
to take advantage of the memoization.