← Back to context

Comment by pfdietz

3 years ago

If you have a function that fails on a substantial number of inputs, random testing is probably a better idea, as it will find a failure in short expected time. An exhaustive testing harness may waste large amounts of time on a segment of the input space it hits first, if that initial segment is free of bugs.

You can use random testing for exhaustive testing. On an input space of size N, you will cover that space completely in O(NlogN) tests on average, and you will include any single input in O(NlogN) trials with high probability.

For many things (like floating-point), saving the computer time is not any kind of goal. It's not gonna complain if you ask it to try all the things.

Further, writing clever shotgun tests may actually take you longer than writing the simple loop. In which case it's wasting developer time too.

Be very sure you need to do anything but exhaustive testing, before expending the time money and effort on it. That's my advice.