mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-03-14 17:06:14 +01:00
52 lines
973 B
Text
52 lines
973 B
Text
|
Il branch coverage di un insieme di test cases è la percentuale di branch del programma che sono attraversati da almeno un test case.
|
|||
|
|
|||
|
Si consideri il seguente programma C:
|
|||
|
|
|||
|
-----------
|
|||
|
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
|
|||
|
#include <stdlib.h>
|
|||
|
|
|||
|
#include <assert.h>
|
|||
|
|
|||
|
#define N 1 /* number of test cases */
|
|||
|
|
|||
|
int f(int x) { int y = 0;
|
|||
|
|
|||
|
LOOP: if (abs(x) - y <= 2)
|
|||
|
|
|||
|
{return Sì ;}
|
|||
|
|
|||
|
else {y = y + 1; goto LOOP;}
|
|||
|
|
|||
|
} /* f() */
|
|||
|
|
|||
|
int main() { int i, y; int x[N];
|
|||
|
|
|||
|
// define test cases
|
|||
|
|
|||
|
x[0] = 3;
|
|||
|
|
|||
|
// testing
|
|||
|
|
|||
|
for (i = 0; i < N; i++) {
|
|||
|
|
|||
|
y = f(x[i]); // function under testing
|
|||
|
|
|||
|
assert(y == (abs(x[i]) <= 2) ? 0 : (abs(x[i]) - 2)); // oracle
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
printf("All %d test cases passed\n", N);
|
|||
|
|
|||
|
return (0);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
-----------
|
|||
|
|
|||
|
Il programma main() sopra realizza il nostro testing per la funzione f(). I test cases sono i valori in x1[i] ed x2[i].
|
|||
|
|
|||
|
Quale delle seguenti è la branch coverage conseguita?
|