Question

Here is an example with the function:

Examining this I believe that it is possible to achieve 100% path coverage.

My understanding of path coverage is that you need to design test cases such that all independent paths in the program are executed at least once.

Looking at the source code and simplified control flow graph I don't see any restrictions that wouldn't allow you to test every single pathway through having multiple test cases. Am I wrong in saying this?

Was it helpful?

Solution

In theory? No. As that would be equivalent to solving the halting problem. You would need to enumerate infinite number of inputs to cover all the possible paths. Which is clearly impossible.

In practice? For some small, simple problems, yes, it is possible. Your example problem demonstrates it.

But for any bigger, real-life problem, it would be both difficult and expensive to do so. Once you start using 3rd party code, you will never know what possible paths the code can take there. And considering such method can have an infinite state as an input, it becomes equivalent to the halting problem.

The closes to this are formal methods of verification of software. But those are slow and expensive and only worth it in limited scenarios, where extreme reliability is necessary.

Licensed under: CC-BY-SA with attribution
scroll top