Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Hamza-Khiar opened this issue Apr 16, 2024 · 3 comments · Fixed by #111
Closed

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

Hamza-Khiar opened this issue Apr 16, 2024 · 3 comments · Fixed by #111
Assignees

Comments

@Hamza-Khiar
Copy link

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

Copy link

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 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
Copy link
Member

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
Copy link
Author

Hamza-Khiar commented Apr 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants