Dealing with randomness
Dealing with randomness in algorithms can be a huge mental block for some people when they try to understand how they might use TDD. TDD is so deterministic, intentional, and controlled that your initial gut reaction to introducing a random process may be to think that it makes TDD impossible. This is a place where TDD actually shines though. Here's how.
Let's pick up where we left off on the simplistic NumberGuesser
from earlier. We're going to add a requirement so that it will randomly choose numbers that the user has guessed, but will also weigh for what is most likely.
To get there, I first have the NumberGuesser
guess whatever the previous number was revealed to be every time I ask for a guess. The test for this looks ...
Get Test-Driven Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.