For this I need to write code in my two functions inputchar() and inputstring(). When I do this I need to get the code coverage when ran against the testme() function to at least 80 percent. While running GCOV I am only getting 17 percent coverage, and have bounced around from 17-23 percent. Do you guys have any suggestions/help? I am new to C and creating random testers like this.
the only code that needs to be modified is inputchar file and the inputstring file
char inputChar()
{
char random = (rand() % 94) + 32;
return random;
}
char *inputString()
{
static char s[6];
s[0] = 'r';
s[1] = 'e';
s[2] = 's';
s[3] = 'e';
s[4] = 't';
s[5] = '\0';
int i;
for(i = 0; i<6;i++) {
s[i]++;
i++;
}
return s;
}
void testme()
{
int tcCount = 0;
char *s;
char c;
int state = 0;
while (1)
{
tcCount++;
c = inputChar();
s = inputString();
printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);
if (c == '[' && state == 0) state = 1;
if (c == '(' && state == 1) state = 2;
if (c == '{' && state == 2) state = 3;
if (c == ' '&& state == 3) state = 4;
if (c == 'a' && state == 4) state = 5;
if (c == 'x' && state == 5) state = 6;
if (c == '}' && state == 6) state = 7;
if (c == ')' && state == 7) state = 8;
if (c == ']' && state == 8) state = 9;
if (s[0] == 'r' && s[1] == 'e'
&& s[2] == 's' && s[3] == 'e'
&& s[4] == 't' && s[5] == '\0'
&& state == 9)
{
printf("error ");
exit(200);
}
}
}
Aucun commentaire:
Enregistrer un commentaire