# Given the following fragment of code, how many tests are required for 100% decision coverage?

if width > length
then
biggest_dimension = width
if height > width
then
biggest_dimension = height
end_if
else
biggest_dimension = length
if height > length
then
biggest_dimension = height
end_if
end_if


Given the following fragment of code, how many tests are required for 100% decision coverage? According to my calculation the answer should be 6 as I am calcualting true and false for each if condition but the actual answer is 4. can someone tell me how it got as 4?

I hope this will help you understand why the answer is 4.

100% Decision coverage

The code traverses 4 paths/decisions for 100% Decision coverage.

This happens when the decision statements are nested. In this case

"height > width" with execute only if "width > length" is true.

"height > length" with execute only if "width > length" is false.

Hence the minimum number of test cases required to cover 100% decision testing is 4.

Edit: As per Polina's request I'm adding explanation for 100% Statement Coverage.

For this same piece of code you can achieve 100% Statement Coverage with just 2 sets of inputs,

Case 1.

Height = 10
Width = 8
Length = 5


In this case,

• if width > length will be true. Hence next statement biggest_dimension = width will be executed.
• if height > width will also be true. Hence next statement biggest_dimension = height will be executed.

Case 2.

Height = 7
Width = 5
Length = 6


In this case,

• if width > length will be false. Hence next statement biggest_dimension = length will be executed.
• if height > length will be true. Hence next statement biggest_dimension = height will be executed.

So you need a minimum of 2 tests for 100% Statement Coverage.

• Thanks for the solution. can you please tell me what will be the statement coverage in this? Feb 26, 2021 at 6:43
• is this is the solution 2 for statement coverage? Feb 26, 2021 at 7:01
• I've added the explanation for statement coverage to the answer. If you think it's help, you can up vote the answer. Feb 26, 2021 at 7:08