Cyclomatic-metric
Question 1 |
With respect to software testing, consider a flow graph G with one connected component. Let E be the number of edges, N be the number of nodes, and P be the number of predicate nodes of G. Consider the following four expressions:
1. E - N + P
2. E - N + 2
3. P + 2
4. P + 1
The cyclomatic complexity of G is given by
1 or 3 | |
2 or 3 | |
2 or 4 | |
1 or 4 |
Question 1 Explanation:
Note: Out of syllabus.
Question 2 |
The cyclomatic complexity of the flow graph of a program provides
an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at most once | |
a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at most once | |
an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once | |
a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at least once |
Question 2 Explanation:
Note: Out of syllabus.
Question 3 |
Consider the following pseudo-code:
IF ((A > B) AND (C > D)) THEN A = A + 1 B = B + 1 ENDIF
The cyclomatic complexity of the pseudo-code is
2 | |
3 | |
4 | |
5 |
Question 3 Explanation:
The cyclomatic complexity of a program can be calculated using the formula:
V(G) = E - N + 2P
Where:
V(G) is the cyclomatic complexity.
E is the number of edges in the control flow graph.
N is the number of nodes in the control flow graph.
P is the number of connected components (usually 1).
In your pseudo code, there are two conditional statements (A > B and C > D), and an "ENDIF" which represents the end of the conditional block. This forms a basic control flow structure.
Let's break it down into a control flow graph:
Start (Node 1)
Condition A > B (Node 2)
Condition C > D (Node 3)
A = A + 1 (Node 4)
B = B + 1 (Node 5)
EndIF (Node 6)
Now, count the number of edges (E) and nodes (N):
E = 7 (7 transitions between nodes)
N = 6 (6 nodes)
Since there is only one connected component (P = 1), we have:
V(G) = E - N + 2P = 7 - 6 + 2 * 1 = 3
So, the cyclomatic complexity of your pseudo code is 3.
Question 4 |
Consider the following C program segment.
while (first <= last) { if (array [middle] < search) first = middle +1; else if (array [middle] == search) found = True; else last = middle – 1; middle = (first + last)/2; } if (first < last) not Present = True;
The cyclomatic complexity of the program segment is __________.
5 | |
6 | |
7 | |
8 |
Question 4 Explanation:
Note: Out of syllabus.