-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
grade-school: align with specification per #503 #555
Conversation
/format |
static void test_a_student_cant_be_in_two_different_grades(void) | ||
{ | ||
TEST_IGNORE(); | ||
roster_t input = { | ||
2, { | ||
(student_t) {2, "Aimee"}, | ||
(student_t) {1, "Aimee"}} | ||
}; | ||
uint8_t desired_grade = 5; | ||
|
||
populate_roster(&input); | ||
|
||
roster_t actual = get_grade(desired_grade); | ||
|
||
TEST_ASSERT_EQUAL(0, actual.count); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is really confusing. How does this ensure that a student can't be in two different grades? "Aimee"
is added to grades 1 and 2, but then it checks that grade 5 is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, copy-pasta error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this some more, the way this test is specified makes me think I should rearchitect this exercise completely.
My first inclination here was to check student names as a student is added, compare it to names already on the list and not add it if the name already exists.
However this supposes a linear timeline of added the input (i.e. add Aimee at grade 2 that succeeds, then attempt to add Aimee at grade 1 that fails). However, the desired grade is specified as 2 with an expected output of zero (implying that actually the addition of Aimee in grade 2 should have failed).
This suggests a much simpler interface like the following, where there is no local store of the roster, it is instead supplied as an input each time a query is made.
typedef struct {
uint8_t grade;
char *name;
} student_t;
typedef struct {
size_t count;
student_t students[MAX_STUDENTS];
} roster_t;
roster_t get_roster(roster_r students);
roster_t get_grade(uint8_t grade, roster_r students);
I realised my idea for simplification of the interface (#555 (comment)) conflicts with the information in the exercise So I have added a check for multiple names in the same grade in the current implementation in the latest commit instead. |
This still isn't right 🙃 |
58f7525
to
00258b5
Compare
00258b5
to
e744fdc
Compare
/format |
Finally! This exercise is at a state it is possible to implement and match the spec 🙌 |
Also corrects first TEST_IGNORE() placement
0233c48
to
8ba1222
Compare
Fixes #503