News for hackers. Stuff that matters.
Re:Solving Algorithmic Problems in Python with Pytest (2019) by matsemann on Saturday December 19, 2020 @08:39AM (#25477313)
If it were a non-trivial example I would split it in two: One function to generate the data, and one function to count and do the statistics. Then you can pass the second one known datasets and verify it gives you correct statistics, and at least be confident that that part is correct.

Of course that still leaves the generation and randomness part. You could make a separate function for numberToTailOrHead(...) that you can test. Or maybe you should have the ability to send in which source of randomness it uses. And then you can provide a fake random implementation that tests the edge cases (0, 0.5, 0.999).

There are no comments on this comment yet.