Estimation of Test Coverage and Structural Complexity

NikulZinzuvadiya 1 views 9 slides Oct 08, 2025
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

Test coverage measures the extent to which the source code of a program is executed when a test suite runs. It helps determine how thoroughly the software has been tested.

Types of coverage:
Statement Coverage: Measures how many statements have been executed.

Branch Coverage: Measures how many bra...


Slide Content

Estimation of Test Coverage and Structural Complexity
Prepared by:
Asst. Prof. Nikul Zinzuvadiya

Test Coverage:
Test coverage measures the extent to which the source code of a program is executed when a test suite
runs. It helps determine how thoroughly the software has been tested.
Types of coverage:
●Statement Coverage: Measures how many statements have been executed.
●Branch Coverage: Measures how many branches (true/false outcomes) of control structures are
executed.
●Path Coverage: Measures whether all possible paths through a function have been executed.
Formula for statement coverage:

Structural Complexity:
Structural complexity is measured using Cyclomatic Complexity (CC), developed by Thomas McCabe.
It indicates the number of linearly independent paths through a program.
Formula:
Where:
●E = number of edges in the control flow graph (CFG)
●N = number of nodes in CFG
●P = number of connected components (usually 1 for a single program)
Alternate formula (using decision points):
Where D = number of decision nodes (like if, while, for, case).

Algorithm / Steps:
1.Write a sample program with some decision statements.

2.Identify the nodes and edges in its Control Flow Graph (CFG).

3.Draw the CFG.

4.Calculate Cyclomatic Complexity using the formula.

5.Identify independent paths.

6.Derive test cases for achieving 100% path coverage.

7.Compute statement and branch coverage.

Example Program (C / C++):
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c)
printf("A is largest\n");
else if (b > c)
printf("B is largest\n");
else
printf("C is largest\n");
return 0;
}

Control Flow Graph (CFG):

You can represent the flow as:
1.Start

2.Read inputs

3.Check (a > b && a > c)

4.If true → “A is largest”

5.Else → check (b > c)

6.If true → “B is largest”

7.Else → “C is largest”

8.End

Start
End

Cyclomatic Complexity Calculation:
Number of Nodes (N) = 8
Number of Edges (E) = 9
Number of Components (P) = 1

Cyclomatic Complexity = 3
Hence, there are 3 independent paths, and 3 test cases are required for complete path coverage.

Test Cases:
Test
Case
ab c Expected OutputExecuted Path
1 105 3 A is largest Path 1
2 5103 B is largest Path 2
3 53 10C is largest Path 3

Test Coverage:
All statements and branches are executed with the above three test cases.
✅ Statement Coverage = 100%
✅ Branch Coverage = 100%
Observation:
●Cyclomatic complexity of the program = 3

●Minimum 3 test cases required for 100% path coverage

●All statements and branches were executed successfully.