nus-cs2113-AY1920S2 / forum

4 stars 0 forks source link

Path coverage and statement coverage #83

Closed Zhilin-Huang closed 4 years ago

Zhilin-Huang commented 4 years ago

Understood from the explanation that 100% path coverage gives the highest intensity, but why doesn't 100% statement coverage give highest intensity as well? Doesn't all statements being executed mean all paths are executed?

image

Any help is appreciated!

damithc commented 4 years ago

Good question @Zhilin-Huang Consider a case of a while-loop in the code. An execution path that does only one iteration through the loop executes all statements in the loop, achieving 100% statement coverage. But that does not mean all unique paths through the loop have been executed because a path that does only one iteration in the loop is different from another path that does two iterations in the loop.

Zhilin-Huang commented 4 years ago

Good question @Zhilin-Huang Consider a case of a while-loop in the code. An execution path that does only one iteration through the loop executes all statements in the loop, achieving 100% statement coverage. But that does not mean all unique paths through the loop have been executed because a path that does only one iteration in the loop is different from another path that does two iterations in the loop.

I see! So does this mean that in the case that we have a while-loop, we can never achieve 100% path coverage because executing 1, 2, 3... n iterations are considered different paths?

damithc commented 4 years ago

I see! So does this mean that in the case that we have a while-loop, we can never achieve 100% path coverage because executing 1, 2, 3... n iterations are considered different paths?

Yes, if the possible number of loops is not a fixed number of possibilities. In other cases it is not impossible but the number of paths can be too big for 100% path coverage to be feasible.

Zhilin-Huang commented 4 years ago

I see! So does this mean that in the case that we have a while-loop, we can never achieve 100% path coverage because executing 1, 2, 3... n iterations are considered different paths?

Yes, if the possible number of loops is not a fixed number of possibilities. In other cases it is not impossible but the number of paths can be too big for 100% path coverage to be feasible.

Thanks for the clarification Prof!