diff --git a/exercises/practice/grade-school/.meta/example.c b/exercises/practice/grade-school/.meta/example.c index 4f5bea107..5791c9aee 100644 --- a/exercises/practice/grade-school/.meta/example.c +++ b/exercises/practice/grade-school/.meta/example.c @@ -24,6 +24,19 @@ static int compare_student_grades_and_names(const void *s1, const void *s2) return compare_student_names(student1, student2); } +static bool are_students_in_multiple_grades(roster_t students) +{ + for (size_t i = 0; i < students.count; ++i) + for (size_t j = 0; j < students.count; ++j) + if (i != j + && !strncmp(students.students[i].name, students.students[j].name, + MAX_NAME_LENGTH) + && students.students[i].grade != students.students[j].grade) + return true; + + return false; +} + bool add_student(char *name, uint8_t grade) { bool added = false; @@ -49,6 +62,9 @@ roster_t get_grade(uint8_t grade) { roster_t grade_roster = { 0 }; + if (are_students_in_multiple_grades(roster)) + return grade_roster; + for (size_t i = 0; i < roster.count && grade_roster.count < MAX_STUDENTS; ++i) { if (roster.students[i].grade == grade) { diff --git a/exercises/practice/grade-school/test_grade_school.c b/exercises/practice/grade-school/test_grade_school.c index 2f3836caf..a5b8b14ca 100644 --- a/exercises/practice/grade-school/test_grade_school.c +++ b/exercises/practice/grade-school/test_grade_school.c @@ -60,7 +60,7 @@ static void test_a_student_cant_be_in_two_different_grades(void) (student_t) {1, "Aimee"}, (student_t) {2, "Aimee"}} }; - uint8_t desired_grade = 5; + uint8_t desired_grade = 2; populate_roster(&input);