100% Path and Decision Coverage

How many test cases are needed to have 100% path coverage and decision coverage in the following code.
if (conditionA)
{
c=c+1
}
if(conditionB)
d=d-1
else
e++

consider condition A and condition B are independent.

Questions by shruti.girdhar

Showing Answers 1 - 24 of 24 Answers

If these conditions A & B are independent. Assuming as these are not
interlinked (as c, d, and e are not affecting each other) you can simply write 4
tests as below:


1. Condition A true value
2. Condition A false value
3. Condition B true value
4. Condition B false value


If they are linked then you can test the below conditions:


1. Condition A true value, Condition B true value
2. Condition A true value, Condition B false value
3. Condition A false value, Condition B true value
4. Condition A false value, Condition B false value


If you are not convinced with these please provide more details.


Regards,
Valusa

tagro82

  • Oct 23rd, 2008
 

Path Coverage is all path covered
So for Condition 1 , as there is no else part so 1 TC
for condition 2, 2 T.C .

Decision Coverage requires 4 T.C

  Was this answer useful?  Yes

bhavikt21

  • Jul 6th, 2009
 

There are 4 different paths
so Path coverage: 4
2 conditions, so 4 decisions
but it can be reduced to 2
Condition 1 Condition2
T F
F T
Actually it also depends on what is the given condition.

Worst case is 4 best case is 2.

  Was this answer useful?  Yes

mohit

  • Dec 5th, 2014
 

path coverage=3
decision coverage=3

  Was this answer useful?  Yes

Lakshmi

  • Feb 8th, 2016
 

DC=2
PC=4

  Was this answer useful?  Yes

Anonymous

  • Dec 8th, 2016
 

DC = 4 (2 for each condition i.e One that evaluates it to True and other false)
PC= 3 (Draw CFG to be more clear)

  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