Statement coverage means every statement had to be executed.
Decision coverage measures the coverage of conditional branches. Branch coverage measures the coverage of conditional and unconditional branches. At 100 %, they give the same result. You can see a discussion on differences between these two here.
1/
I added spaces so it's a bit more readable.
Read A
Read B
if A>0 then
if B>0 then
print "No Valid"
else
print "B"
if A = 21 then
print A
End if
End if
End if
Statement coverage could be achieved with one input value:
A=1, B=1
A=21, B=0
Decision coverage and branch coverage could be achieved with these input values:
A=0, B=0
A=21, B=0
A=20, B=0
A=21, B=1
2/
I added "if" on the 3rd line since I believe it was missing. I also added spaces so it's a bit more readable.
Read A
if A > 0 THEN
if A = 12 THEN
Print "Hey"
End if
End if
Statement coverage could be achieved with one input value: A=12
.
Decision coverage and branch coverage could be achieved with these input values:
A=12
A=13 (or any other value greater than 0 and not equal to 12)
A=0 (or any other value less than or equal to 0)
Note that some of the values are just random values that will fit in in order to cause some decision to true or false, but my choice of values is not the only correct one, you can choose different values and achieve the same result.
Edit: PDHide mentioned decision coverage and branch coverage are not the same, which is true. I updated my post slightly to better explain it, plus I deleted the link to an article that might have mentioned these two coverages are the same. I didn't change the values since if you want to achieve 100 % branch or decision coverage, you can use the same values here.
If you are concerned about the number of test cases that you need in order to achieve 100 % branch and decision coverage, than this can differ in some situations like:
function test(a, b):
return a > 0 and b < 10
In this example, there's one decision and no branch. Therefore, you need two test cases to achieve 100 % decision coverage, but one test case to achieve 100 % branch coverage.
To illustrate than is means by conditional and unconditional branches, let's consider this example:
if A = 12 THEN
Print A
End if
Print 0
Here, there're two conditional branches and one unconditional branch:
