Statement Coverage
Description
A statement is a valid line of code according to the C/C++ standard.
This metric indicates the percentage of source code statements that execute in the current test cases. For instance, a value of 50% indicates that the current test cases invoke only half of the statements in your code at least once. To increase statement coverage, add test cases that can execute the untested statements.
Polyspace Implementation
Polyspace® counts the number of valid C or C++ statements in your code (n_total). Then, when running a test, Polyspace counts which lines are executed (n_exec) and computes the statement coverage as:
Statement coverage = (n_exec / n_total) *100#include<stdio.h>
int foo(int x) //1
{
if (x > 0) //2
return -1; //3
else if (x < 0) //4
return 1; //5
else
return 0; //6
} foo() with x == -1, lines 1,2,4, and 5 are executed, resulting in a statement coverage of 4/6×100 or 67%.Examples
Version History
Introduced in R2023b