Assignment 01 White Box Testing: Part A
Assignment 01 White Box Testing: Part A
Assignment 01 White Box Testing: Part A
Assignment 01
a. Find the cyclomatic complexity of the graph using both formulas we studied in class. You
can also make changes on CFG if formula requires it.
b. Identify and state minimum number of paths to give
a. 100 % statement coverage.
b. 100 % branch Coverage.
Solution Question 1:
Part a:
Modified graph:
Cyclomatic Complexity:
We can determine Cyclomatic Complexity by two methods:
Here
E=14; N=10
V (G) = 14-10+2 = 6.
So P=5;
V (G) = 5+1 = 6.
Part b:
100% Statement Coverage:
Total Unique paths:
1. First -> A -> B1 -> B2 -> D -> F -> G -> Last
2. First -> A -> B1 -> C -> D -> F -> G -> Last
3. First -> A -> B1 -> C-> F -> G -> Last
4. First -> A -> B1 -> B2 -> E -> D -> F -> G -> Last
5. First -> A -> B1 -> B2 -> E -> F -> G -> Last
6. First -> A -> B1 -> B2 -> D -> F -> G -> A -> B1 -> C -> F -> G -> A ->B1 -> B2 -> E ->F ->G ->
Last
If we choose Path no 6 then we would get 100% statement coverage. So Only 1 path
required.
Read A
Read B
Read C
IF ((A-B < 10 && A+B > 30) || C > 50)
THEN Print "Something"
ENDIF
IF ((A == 15 || B < 15) && C < 14)
THEN Print "Another Thing"
ENDIF
First Number the code so that we can make flow diagram to make it easy to understand.
1. Read A
2. Read B
3. Read C
4. IF ((A-B < 10 && A+B > 30) || C > 50)
5. THEN Print "Something"
6. ENDIF
7. IF ((A == 15 || B < 15) && C < 14)
8. THEN Print "Another Thing"
9. ENDIF
2. 25 4 51 Something 6.25%
3. 26 16 49 - 6.25%
4. 26 16 51 Something 6.25%
5. 25 4 49 - 6.25%
6. 25 4 51 Something 6.25%
7. 17 14 13 Something 12.25%
Another Thing
8. 25 16 51 - 6.25%
9. 25 16 13 - 6.25%
10. 25 14 51 - 6.25%
14. 15 14 51 - 6.25%
15. 15 14 13 Another Thing 6.25%
16. 15 15 51 - 6.25%
C. Test cases for Branch coverage:
4. 16 15 15 - 25%
Step 2:
Compute Cyclomatic Complexity:
By Predicate Node Formula:
CC = P+1
CC = 2+1 =3
Step 3:
1. Start -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> End
2. Start -> 1 -> 2 -> 3 -> 4 -> 6 -> 7 -> 8 -> 9 -> End
3. Start -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 9 -> End
4. Start -> 1 -> 2 -> 3 -> 4 -> 6 -> 7 -> 9 -> End
Step 4:
3. 15 12 13 Another Thing 2
====================================THE END====================================