remisharrock / c-programming-with-linux-MOOC-issues-tracker

7 stars 0 forks source link

Not enough test on activity about finding t (course 2) #447

Closed deladan closed 2 years ago

deladan commented 5 years ago

In activity: is there a 't' in this word? (course 2), case where "t" is the first letter of a even-length word isn't tested.
So program which doesn't treat differently even or odd words is accepted all the same.
For instance this one:

#include <stdio.h>
int main(void)
{
    char word[51];
    int length = 0;
    int i,found, maxindex;

    scanf("%s", word);

    while (word[length]!='\0')
        length++;
    maxindex = length/2;

    i = 0;
    found = 0;
    while (!found && i < length) {
        if (word[i]=='t' || word[i]=='T') found++;
        else i++;
    }

    if (!found) 
        printf("-1");
    else if (i <= maxindex) printf("1");
    else printf("2");

    return 0;
}

even if it fails on input as "cats".

Link to the activity: https://courses.edx.org/courses/course-v1:Dartmouth_IMTx+DART.IMT.C.02+1T2018/courseware/f2a41407085b4e8c8a5604123388ef33/d8915bd231464784b2f66b097349333e/4?activate_block_id=block-v1%3ADartmouth_IMTx%2BDART.IMT.C.02%2B1T2018%2Btype%40discussion%2Bblock%401239b3bbe75a4c3ca5bee09225cc1695

deladan commented 5 years ago

Another missing test for this activity ? Some learner wrote a program that prints 3 if t letter is found in both parts of the name, and he/she said his/her program was accepted by the grader.

deladan commented 5 years ago

Another incorrect code which is accepted as well:

#include <stdio.h>
int main(void)
{
    char word[50];
    scanf("%s", word);
    int i = 0;
    int j = 0;
    int n = 0;
    int found = 0;
    while(word[i] != '\0')
    {
        i++;
    }
    n = i/2;
    j = 0;
    while ( word[j] != '\0' && found == 0)
    {
        if(word[j] == 't' || word[j] == 'T')
        {
            found = 1;
        }
        j++;
    }
    if(found == 0)
    {
        printf("-1");
    }else if(j<=n)
    {
        printf("1");
    }else if(j>n)
    {
         printf("2");
    }
    return 0;
}

which prints out 2 for input such as "enter", while "1" is the expected answer.

deladan commented 3 years ago

Another incorrect program which has been accepted by the grader:

#include<stdio.h>
int main(void){
    char word[51];
    int i=0;
    int k=0;
    int half;
    char a='t';
    char b='T';
    scanf("%s",word);
    while(word[i]!='\0'){
        i++ ;
    }
     half = i/2;
     while( word[k]!='\0'&&(word[k] != 't' || word[k] != 'T')){
         if((word[k]==a || word[k]==b)&&k<half){
             printf("%d",1);
             break;
         }else if((word[k]==a || word[k]==b)&&k>half) {
             printf("%d",2);
             break;
         }else{
             k++;
         }
        }if(word[k]==0){
         printf("%d",-1);
        }
        return 0;
}

Once again, it doesn't give expected result for entries like "enter", where 't' is exactly in the middle of an uneven long word. Shouldn't some test be added?