Making Tests Repeatable—Continued

Let’s continue writing tests for impure functions.

Random numbers

We’ve successfully dodged the idea of random numbers, but it’s time to pay the piper. We have to solve for the fact that we don’t have repeatable results when we generate a question using random numbers, so we’ll have to improvise.

We can use streams to generate many random numbers, and then narrow that value to the one we need. We’ll be entering this now in /test/question_test.exs:

Get hands-on with 1400+ tech skills courses.