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

sorts solutions prior to check #932

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions exercises/practice/word-count/test_word_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ void tearDown(void)
{
}

static int cmp_word_count_word(const void *a, const void *b){
elmq0022 marked this conversation as resolved.
Show resolved Hide resolved
word_count_word_t *w1 = (word_count_word_t *)a;
word_count_word_t *w2 = (word_count_word_t *)b;
return strcmp(w1->text, w2->text);
}

static void check_solution(word_count_word_t *expected_solution,
int expected_word_count,
word_count_word_t *actual_solution,
Expand All @@ -25,6 +31,10 @@ static void check_solution(word_count_word_t *expected_solution,
// All words counted?
TEST_ASSERT_EQUAL(expected_word_count, actual_word_count);

// Sort the words before comparing
qsort(expected_solution, expected_word_count, sizeof(word_count_word_t), cmp_word_count_word);
qsort(actual_solution, actual_word_count, sizeof(word_count_word_t), cmp_word_count_word);

// now test the word count for the words...
for (int index = 0; index < MAX_WORDS; index++) {
TEST_ASSERT_EQUAL(expected_solution[index].count,
Expand Down
Loading