Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Software Testing Spring 2021

Assignment 01

White Box Testing

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:

By Edges and Nodes Formula Method:


V (G) = E - N + 2
Where E= Edges and N= Nodes;

Here

E=14; N=10

V (G) = 14-10+2 = 6.

By Predicate Nodes Method:


V (G) = P+1
Where P is no of predicate nodes so

Here Predicate nodes are B1, B2, C, E and G.

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.

100% Branch 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 2, 4, 6 then we would get 100% statement coverage. So 3 Paths
required.

QUESTION 2: CONTROL FLOW TESTING:

For the following code perform the following


A. Write test cases for statement coverage.
B. Write test cases for condition coverage.
C. Write test cases for branch coverage.
D. Perform all steps of basis path testing.

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

Control flow Graph:


Solution Question no 2:
A. Test cases for statement coverage:
There is one test case that covers all the statements.
Test Case Value of A Value of B Value of C Output Statement
Coverage
1. 17 14 13 Something 100%
Another Thing

B. Test cases for Condition coverage:

Test Case Value of A Value of B Value of C Output Branch


Coverage
1. 25 4 49 - 6.25%

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%

11. 25 14 13 Another Thing 6.25%


12. 15 16 49 - 6.25%
13. 15 14 49 - 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:

Test Case Value of A Value of B Value of C Output Branch


Coverage
1. 17 14 13 Something 25%
Another Thing
2. 16 15 51 Something 25%

3. 15 15 13 Another Thing 25%

4. 16 15 15 - 25%

D. Perform all steps of basis path


testing.
Step 1:

Control flow Graph:

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:

Test Case Value of A Value of B Value of C Output Path


1. 15 17 13 Something 1
Another Thing
2. 15 16 51 Something 4

3. 15 12 13 Another Thing 2

====================================THE END====================================

You might also like