#Rust - grade school
61 messages ยท Page 1 of 1 (latest)
so it sounds like we have 2 tests with two different outputs and attributes we care about
- Name
- Grade
the key phrase on the challenge page says: "each student cannot be added more than once to a grade or the roster".
this is called a constraint on your code you're trying to get out through your tests. try to think of an simple input where you add the same person twice
'''
add (name: jim, grade: 2)
add(name:jim, grade 2)
'''
thinking of the requirement: "Get a list of all students enrolled in a grade:": how many people are on the roster really?
If you change the single quotes to backticks you get formatted codeblocks. ```
i was typing on a phone lol i couldn't find the backtick on an ios keyboard ugh
"each student cannot be added more than once to a grade or the roster". I tried this as well. However, there is another test case that wants us to allow the same student to be added on multiple grades!!
"to a grade" vs "multiple grades"
There are basically two test cases: one asks us to add a student to multiple grades. Another asks us to disallow a student from adding to multiple grades.
And we cannot pass them both, can we ๐
To check whether I have made some mistake, I tried running some of the community solutions. They fail to the test cases now. Is there a possibility that the test cases have been changed recently. Can you have a look at this
Which test fails when you allow the same name in multiple grades?
This exercise hasn't changed since a year ago. https://github.com/exercism/rust/commits/main/exercises/practice/grade-school
student_not_added_to_other_grade_for_multiple_grades() this one
I am getting a mixup with the above and student_not_added_to_multiple_grades()
Both of these test for the grade() function and expect different results
Both have "not added" in the name. Which one expects a student to get added?
As per the test case, we can add a student to different grades. However, one of these test cases expect us to return students from a grade that is not present in other grade, while the other expects us to return all the students in a grade
And both of these call the grade() function
As per the test case, we can add a student to different grades.
Which test expects the student to be registered twice?
We can add a student to multiple grades in the entire program.
Since I have passed all the other cases, I am expecting that this is the case. Any I can pass one of these two test cases at once
Yes
The two tests are calling the same function, but they expect different answers from it
Do they call the same function with the same arguments or with different arguments?
Is there any specific test that requires you can add a students to multiple grades? As you pointed out, there are tests that require a student cannot be added to multiple grades. If there is no test that allows for it, then the tests consistently do not allow it and your code should not allow it.
These are the two test cases. Both call the grade() function, but expect different answers
Do they call the same function with the same arguments or with different arguments?
There are no test cases, that prevent us from adding a student to multiple classes. Therefore, we are allowed to do that
They are calling the same function with the grade argument as per the screenshot above.
There are basically two test cases: [...] Another asks us to disallow a student from adding to multiple grades.
That sounds like the tests disallow it.
Is the grade argument the same value or a different value?
What is the grade argument in the first failing test? What is it in the second failing test?
In this case the first one is 2 and another is 3 for different grades. But if you look closely for 3: It expects to return just Paul and not Paul and James, while for the argument 2(which is failing), it expects to return both Blair and James
So they are testing different things, right? What does the 2 mean vs the 3?
2 and 3 are jsut the grades that are being mapped to the students in each grade
2: All the students in grade 2, 3: All the students in grade 3, and so on
Right. So what grade is James added to?
let mut s = School::new();
s.add(2, "Blair");
s.add(2, "James");
s.add(3, "James");
s.add(3, "Paul");
James have been added to both grades
But if you look closely for 3: It expects to return just Paul and not Paul and James, while for the argument 2(which is failing), it expects to return both Blair and James
Which grade do the tests expect James to be in?
Note the test name, student_not_added_to_multiple_grades
Ohh ๐ . I think i got it. It is in sequencial. So i guess, we are not allowed to add a student in more that 1 grade. Is that so?
That's what you've stated before. That sounds like a good assumption.
Computers usually do things sequentially.
Yeah. I just saw that now. LOOKING at the test cases, the way it was being added, i thought that the same student was allowed to be added on multiple grades
But that does not seem to be the case. So basically grade() expects us to return all the students in that grade. It is not adding James the second time.
The test name says not added ๐
Correct
While solving it, i made another mistake as well. I was adding a student yo the new grade and removing the student from the older one. I am guessing we are not allowsled to add a student to a new grade at all
Look at what behavior those tests expect ๐ That's what your code should do.
But that does not seem to be the case. So basically grade() expects us to return all the students in that grade. It is not adding James the second time.
This sounds right to me.
You're welcome. Good luck.
Solved!! Thanks once again Isaac
You're welcome