Questions about the statement coverage, branch coverage and path coverage

1.1k Views Asked by At

enter image description here

enter image description here

I am really confuse with the statement coverage. I did some search on the Internet. Some say the statement coverage only go through the true condition, which in this case is 1-2-3-4-12. However, others say the statement coverage should cover as many statements as possible, which I believe in this case will be 1-2-3-5-6-7-8-9-10-11-12. Which one is correct?

For the branch coverage, I believe I should test both the true/false conditions without considering the loop, which I will use the value 1)x=-1 and 2)x=0

For the path coverage, I think I should test all the paths so compared to branch coverage I will need to test the loop also. So I am going to use the value 1) x= -1, 2)x = 0 and 3) x = 10.

Is my answers correct?

Thank you in advance

2

There are 2 best solutions below

0
On

To calculate Statement Coverage, find out the shortest number of paths following which all the nodes will be covered.

So in your case : 1-2-3-5-6-7-8-9-10-11-12 This path is the shortest and covering maximum number of nodes but not all

so we have to take one more path , which is : 1-2-3-4-12

So in this exercise , the value of SC=2

0
On
  1. I think "statement coverage" refers to "meaningful/useful/normal".
  2. The nubmer of statement may vary by breaking one statement into two.
  3. The "true" condition may not be useful for us just like the example you gave. Normally we want a positive number to get its factorial. You can switch the "true" and "false" conditions whatever you like.