exercism / c-test-runner

GNU Affero General Public License v3.0
5 stars 5 forks source link

issue with the test-runner on a C exercise #110

Closed Hamza-Khiar closed 6 months ago

Hamza-Khiar commented 6 months ago

the exercise was the isogram exercise.

the exercise was done locally at first, downloaded the exercise and solved it in place and all the test were passing image

but when i submit the the iteration to the website i get this error;

An error occurred while running your tests. This might mean that there was an issue in our infrastructure, or it might mean that you have something in your code that's causing our systems to break.

Please check your code, and if nothing seems to be wrong, try running the tests again.

i couldn't understand what makes it fail when submitted but passes locally.

so here i am i guess there is an issue with the test runner cause when i asked on the discord group, i was told to add a \n for the printf cause it messes with the test-runner.


//isogram.h
#ifndef ISOGRAM_H
#define ISOGRAM_H

#include <stdbool.h>

bool is_isogram(const char phrase[]);

#endif

// isogram.c

#include "isogram.h"
#include <stdio.h>
#include <string.h>

bool is_isogram(const char phrase[]){

    int j=0;
    unsigned short alphabet_poz[52][2];
    unsigned short phrase_len,alphabet_poz_len;

    if (phrase==NULL) {
        return false;
    }

    for (char alpha='A'; alpha<='Z'; alpha++) {
        alphabet_poz[j][0]=alpha;
        alphabet_poz[j][1]=0;
        j++;
    }
    for (char alpha='a'; alpha<='z'; alpha++) {
        alphabet_poz[j][0]=alpha;
        alphabet_poz[j][1]=0;
        j++;
    }

    phrase_len=strlen(phrase);
    alphabet_poz_len=(sizeof(alphabet_poz)/sizeof(alphabet_poz[0]))/2;

    for (int idx=0; idx<=phrase_len; idx++) {
        for (int iterv0=0 ; iterv0<alphabet_poz_len ; iterv0++) {
            int iterv1=iterv0+26;
            //printf("how true :%d\n", (alphabet_poz[iterv0][0]==phrase[idx]) || (alphabet_poz[iterv1][0]==phrase[idx]));
            if ((alphabet_poz[iterv0][1]==1 || alphabet_poz[iterv1][1]==1) && (phrase[idx]==alphabet_poz[iterv0][0] || phrase[idx]==alphabet_poz[iterv1][0])) {
                printf("it's not an isogram");
                return false;
            }
            if ((alphabet_poz[iterv0][0]==phrase[idx]) || (alphabet_poz[iterv1][0]==phrase[idx])) {
                alphabet_poz[iterv1][1]++;
                alphabet_poz[iterv0][1]++;
                continue;
            }

        }
    }
    printf("it's an isogram");
    return true;
}

here's my implementation

github-actions[bot] commented 6 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link/2;%0D%0A%0D%0A%20%20%20%20for%20(int%20idx=0;%20idx%3C=phrase_len;%20idx++)%20%7B%0D%0A%20%20%20%20%20%20%20%20for%20(int%20iterv0=0%20;%20iterv0%3Calphabet_poz_len%20;%20iterv0++)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20int%20iterv1=iterv0+26;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20//printf(%22how%20true%20:%25d%5Cn%22,%20(alphabet_poz%5Biterv0%5D%5B0%5D==phrase%5Bidx%5D)%20%7C%7C%20(alphabet_poz%5Biterv1%5D%5B0%5D==phrase%5Bidx%5D));%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((alphabet_poz%5Biterv0%5D%5B1%5D==1%20%7C%7C%20alphabet_poz%5Biterv1%5D%5B1%5D==1)%20&&%20(phrase%5Bidx%5D==alphabet_poz%5Biterv0%5D%5B0%5D%20%7C%7C%20phrase%5Bidx%5D==alphabet_poz%5Biterv1%5D%5B0%5D))%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20printf(%22it's%20not%20an%20isogram%22);%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20false;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((alphabet_poz%5Biterv0%5D%5B0%5D==phrase%5Bidx%5D)%20%7C%7C%20(alphabet_poz%5Biterv1%5D%5B0%5D==phrase%5Bidx%5D))%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alphabet_poz%5Biterv1%5D%5B1%5D++;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alphabet_poz%5Biterv0%5D%5B1%5D++;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%0D%0A%0D%0A%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20printf(%22it's%20an%20isogram%22);%0D%0A%20%20%20%20return%20true;%0D%0A%7D%0D%0A%60%60%60%0D%0Ahere's%20my%20implementation&category=c ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

ryanplusplus commented 6 months ago

Hey @Hamza-Khiar, I played around with your solution and it looks like it is because of the missing newlines as you mentioned. I suspect that what's happening is that the test runner is having trouble parsing the the test output because of your prints. It expects the outputs to look something like this:

test_isogram.c:107:test_empty_string:PASS
test_isogram.c:108:test_null:PASS
test_isogram.c:109:test_isogram_with_only_lower_case_characters:PASS
test_isogram.c:110:test_word_with_one_duplicated_character:PASS
test_isogram.c:111:test_word_with_one_duplicated_character_from_end_of_alphabet:PASS
test_isogram.c:112:test_longest_reported_english_isogram:PASS
test_isogram.c:113:test_word_with_duplicated_letter_in_mixed_case:PASS
test_isogram.c:114:test_word_with_duplicated_letter_in_mixed_case_lowercase_first:PASS
test_isogram.c:115:test_hypothetical_isogrammic_word_with_hyphen:PASS
test_isogram.c:116:test_hypothetical_word_with_duplicated_character_following_hyphen:PASS
test_isogram.c:117:test_isogram_with_duplicated_hyphen:PASS
test_isogram.c:118:test_made_up_name_that_is_an_isogram:PASS
test_isogram.c:119:test_duplicated_character_in_the_middle:PASS
test_isogram.c:120:test_same_first_and_last_characters:PASS
test_isogram.c:121:test_word_with_duplicated_character_and_with_two_hyphens:PASS

When it looks like this, a regex can match whole lines. With your solution, the output looks like:

it's an isogramtest_isogram.c:107:test_empty_string:PASS
test_isogram.c:108:test_null:PASS
it's an isogramtest_isogram.c:109:test_isogram_with_only_lower_case_characters:PASS
it's not an isogramtest_isogram.c:110:test_word_with_one_duplicated_character:PASS
it's not an isogramtest_isogram.c:111:test_word_with_one_duplicated_character_from_end_of_alphabet:PASS
it's an isogramtest_isogram.c:112:test_longest_reported_english_isogram:PASS
it's not an isogramtest_isogram.c:113:test_word_with_duplicated_letter_in_mixed_case:PASS
it's not an isogramtest_isogram.c:114:test_word_with_duplicated_letter_in_mixed_case_lowercase_first:PASS
it's an isogramtest_isogram.c:115:test_hypothetical_isogrammic_word_with_hyphen:PASS
it's not an isogramtest_isogram.c:116:test_hypothetical_word_with_duplicated_character_following_hyphen:PASS
it's an isogramtest_isogram.c:117:test_isogram_with_duplicated_hyphen:PASS
it's an isogramtest_isogram.c:118:test_made_up_name_that_is_an_isogram:PASS
it's not an isogramtest_isogram.c:119:test_duplicated_character_in_the_middle:PASS
it's not an isogramtest_isogram.c:120:test_same_first_and_last_characters:PASS
it's not an isogramtest_isogram.c:121:test_word_with_duplicated_character_and_with_two_hyphens:PASS

As a result, it can't find any test results because they're mixed in with your outputs and look less unambiguously like test results. It does tolerate printf output as long as it's terminated with newlines so that it can still match whole lines:

it's an isogram
test_isogram.c:107:test_empty_string:PASS
test_isogram.c:108:test_null:PASS
it's an isogram
test_isogram.c:109:test_isogram_with_only_lower_case_characters:PASS
it's not an isogram
test_isogram.c:110:test_word_with_one_duplicated_character:PASS
it's not an isogram
test_isogram.c:111:test_word_with_one_duplicated_character_from_end_of_alphabet:PASS
it's an isogram
test_isogram.c:112:test_longest_reported_english_isogram:PASS
it's not an isogram
test_isogram.c:113:test_word_with_duplicated_letter_in_mixed_case:PASS
it's not an isogram
test_isogram.c:114:test_word_with_duplicated_letter_in_mixed_case_lowercase_first:PASS
it's an isogram
test_isogram.c:115:test_hypothetical_isogrammic_word_with_hyphen:PASS
it's not an isogram
test_isogram.c:116:test_hypothetical_word_with_duplicated_character_following_hyphen:PASS
it's an isogram
test_isogram.c:117:test_isogram_with_duplicated_hyphen:PASS
it's an isogram
test_isogram.c:118:test_made_up_name_that_is_an_isogram:PASS
it's not an isogram
test_isogram.c:119:test_duplicated_character_in_the_middle:PASS
it's not an isogram
test_isogram.c:120:test_same_first_and_last_characters:PASS
it's not an isogram
test_isogram.c:121:test_word_with_duplicated_character_and_with_two_hyphens:PASS

On an unrelated note, it's a good practice to put newlines at the end of your debug prints because C uses buffered output and won't necessarily print all output if your code crashes before a newline is printed which can lead to confusing debug sessions.

Hamza-Khiar commented 6 months ago

thank you for the fix; and sure next time i'll try to implement a more sophisticated debugging method rather than printf debugging one.

On Wed, Apr 17, 2024 at 7:18 AM wolf99 @.***> wrote:

Hi @Hamza-Khiar https://github.com/Hamza-Khiar

Just to add to what @ryanplusplus https://github.com/ryanplusplus has already explained, the exercise does not specify, and the tests to not expect, any printed output.

On the other hand I don't think this is forbidden either. And of course it does highlight a difference between local and remote execution.

The question is then if there is a good way to solve this, or if we suggest that students should only implement output that which the exercise seeks as output.

— Reply to this email directly, view it on GitHub https://github.com/exercism/c-test-runner/issues/110#issuecomment-2060460884, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4I7OG7GPUAPXL3AIS3T5PTY5YH4JAVCNFSM6AAAAABGJ5P6ZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRQGQ3DAOBYGQ . You are receiving this because you were mentioned.Message ID: @.***>