How to calculate Branch and statement coverage for these?

Switch PC on
Start “outlook”
IF outlook appears THEN
Send an email
Close outlook

a) 1 test for statement coverage, 1 for branch coverage
b) 1 test for statement coverage, 2 for branch coverage
c) 1 test for statement coverage. 3 for branch coverage
d) 2 tests for statement coverage, 2 for branch coverage
e) 2 tests for statement coverage, 3 for branch coverage

IF A > B THEN
C = A – B
ELSE
C = A + B
ENDIF
Read D
IF C = D Then
Print “Error”
ENDIF

a) 1 test for statement coverage, 3 for branch coverage
b) 2 tests for statement coverage, 2 for branch coverage
c) 2 tests for statement coverage. 3 for branch coverage
d) 3 tests for statement coverage, 3 for branch coverage
e) 3 tests for statement coverage, 2 for branch coverage

Questions by hereforquestions

Editorial / Best Answer

Answered by: Kaizen

  • Jan 16th, 2016


Can someone help my with this? Minimum test Required for Branch Coverage and Statement coverage: Disc = 0 Order-qty = 0 ReadnOrder-qty If Order-qty >= 20 then Disc = 0.05 If Order-qty >= 100 then Disc = 0.1 else Disc = 0.02 End if End if

Showing Answers 1 - 7 of 7 Answers

manjili

  • Oct 14th, 2008
 

IF A > B THEN
C = A – B
ELSE
C = A + B
ENDIF
Read D
IF C = D Then
Print “Error”
ENDIF

a) 1 test for statement coverage, 3 for branch coverage
b) 2 tests for statement coverage, 2 for branch coverage
c) 2 tests for statement coverage. 3 for branch coverage
d) 3 tests for statement coverage, 3 for branch coverage
e) 3 tests for statement coverage, 2 for branch coverage

maguschen

  • Jul 2nd, 2009
 

Question first:
b) 1 test for statement coverage, 2 for branch coverage
a) Outlook appears == True, fulfill the statement coverage
b) Outlook appears ==
True and outlook appears == False fulfill the branch coverage

Question second:
b) 2 tests for statement coverage, 2 for branch coverage
Test data should be:
a) A>B, C==D
b) A

gchaganti

  • Sep 7th, 2009
 

For First Question
a) 1 test for statement coverage, 1 for branch coverage.

For Second Question
c) 2 tests for statement coverage. 3 for branch coverage.

  Was this answer useful?  Yes

sami

  • Sep 15th, 2011
 

1) exercise:
1 statment coverage
2 Branch covergae

2) exercise
2 statment coverage
3 brance coverage

  Was this answer useful?  Yes

Chanchal

  • Sep 16th, 2011
 

For 1st question: Answer is a.
For 2nd question: Answer is b.

  Was this answer useful?  Yes

Nishant jain

  • Jan 24th, 2012
 

For both the questions Option B is correct.

utsav shah

  • Jan 19th, 2015
 

Ans is B

  Was this answer useful?  Yes

neha k

  • Feb 21st, 2015
 

I think for the 1st ex
1 statement coverage and 2 branch coverage,
As statement coverage means best possible path to cover all the nodes
and Branch coverage means possible path to cover all the edges.

Kaizen

  • Jan 16th, 2016
 

Can someone help my with this?
Minimum test Required for Branch Coverage and Statement coverage:
Disc = 0
Order-qty = 0
ReadnOrder-qty
If Order-qty >= 20 then
Disc = 0.05
If Order-qty >= 100 then
Disc = 0.1
else Disc = 0.02
End if End if

sanidhaya sharma

  • Apr 5th, 2016
 

1-b
2-b

  Was this answer useful?  Yes

Pradeep

  • Dec 20th, 2016
 

b) 1 test for statement coverage, 2 for branch coverage

  Was this answer useful?  Yes

Chirag

  • Feb 20th, 2018
 

So, considering the definitions above and taking some test cases ::
Test Case 1 :: A = 10, B = 11, D = 21
Statements Covered = 1, 2, 3, 5, 6, 7, 8, 9, 10.
Test Case 2 :: A = 11, B = 10, D = 10
Statements Covered = 1, 2, 3, 4, 7, 8, 10.
So, if you look at the Statements covered, you would realize that only 2 test cases are needed to cover all the statements.
Now, coming to Branch Coverage
If you make a program flow diagram of the above code, and going by the definition above, there is a branch at statement 3 and at statement 8, since they are if conditions so, they can be either true or false hence the branch is there. So, the definition of the Branch Coverage says that we need to traverse each branch in the program.
Since from 3 I can go to either 4 or 5 (the 2 branches), let us say the branch 3 to 4 is 3L and branch 3 to 5 is 3R (L and R mean left and right). Similarly for statement 8, the 2 branches can be 8 to 10 (if C != D) and 8 to 9 and then 10. Let these 2 branches be then called 8L and 8R respectively. (Just naming for understanding)
So, from Test Case 2 you can realize that you have covered your branch 3L and 8R from Test Case 1, you can realize you have covered your branch 3R and 8L
So, with just 2 test cases you have covered all your branches and statements.
Hope it makes you clear! Tried my best to do so. Just in case you dont understand try making a program flow graph and re-reading the answer.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions