November 2017
Intermediate to advanced
386 pages
9h 22m
English
Testing the memoization higher-order function poses an interesting problem -- just how would you go about it? The first idea would be to look into the cache -- but that's private and not visible. Of course, we could change memoize() to use a global cache, or to somehow allow external access to the cache, but doing that sort of internal exam is frowned upon: you should try to do your tests based on external properties only.
Accepting that we should omit trying to examine the cache, we could go for a time control: calling a function such as fib(), for a large value of n, should take quite longer if the function were not memoized. This is certainly possible, but it's also prone to possible failures: something external to ...