Test-Adequacy Assessment Using Program Mutation
Example 7.39: Consider again the function trim from the book by
Kernighan and Ritchie.
/* This function is from page 65 of the book by Kernighan and
Ritchie. */
int trim (char s [ ] )
S
1
{
intn; F9
S
2
for (n = strlen(s)-1; n >= 0; n−−)
S
3
if(s[n]!=’’&&s[n]!=’\ t’ && s [n] !=
’\ n’)
S
4
break;
S
5
s[n+1 ] = ’\0’;
S
6
return n;
}
The following two mutants are generated when trim is mutated using the
SMVB operator:
/* This is a mutant generated by the SMVB. In this one, the for loop
body extends to include the s [n+1] = ’\0’ statement. */
int trim (char s [ ] )
{
int n;
for(n=strlen(s)-1; n>=0;n−−){ M20
if (s [n] != ’ ’ && s [n] != ’\ t’ && s [n] != ’\ n’)
break;
s[n+1]=’\ 0’;
}
return n;
}
/* This is another mutant generated by the ...