Stochastic memoization plus more tests.