#Rust - grade school

61 messages ยท Page 1 of 1 (latest)

limpid rampart
#

The rust grade school has two test cases for the pub fn grade(&self, grade: u32) -> Vec<String> {} function. One is to return all the students present in the given grade, and the other is to return only those strudents that are enrolled in the given grade, and no other grades. Can someone help me with this ambiguity?

sleek coral
sleek coral
#

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?

thin locust
#

If you change the single quotes to backticks you get formatted codeblocks. ```

sleek coral
#

i was typing on a phone lol i couldn't find the backtick on an ios keyboard ugh

limpid rampart
#

"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!!

thin locust
#

"to a grade" vs "multiple grades"

limpid rampart
#

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

thin locust
#

Which test fails when you allow the same name in multiple grades?

limpid rampart
#

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

thin locust
#

Both have "not added" in the name. Which one expects a student to get added?

limpid rampart
#

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

thin locust
#

As per the test case, we can add a student to different grades.
Which test expects the student to be registered twice?

limpid rampart
#

We can add a student to multiple grades in the entire program.

thin locust
#

Where do you see that ?

#

Did you look at what the test is doing?

limpid rampart
#

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

thin locust
#

Do they call the same function with the same arguments or with different arguments?

thin locust
limpid rampart
limpid rampart
# limpid rampart

These are the two test cases. Both call the grade() function, but expect different answers

thin locust
#

Do they call the same function with the same arguments or with different arguments?

limpid rampart
limpid rampart
thin locust
thin locust
#

What is the grade argument in the first failing test? What is it in the second failing test?

limpid rampart
thin locust
#

So they are testing different things, right? What does the 2 mean vs the 3?

limpid rampart
#

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

thin locust
#

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");
limpid rampart
#

James have been added to both grades

thin locust
#

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

limpid rampart
#

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?

thin locust
#

That's what you've stated before. That sounds like a good assumption.

#

Computers usually do things sequentially.

limpid rampart
#

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.

thin locust
#

The test name says not added ๐Ÿ˜‰

limpid rampart
#

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

thin locust
limpid rampart
#

Okay

#

Thank you for your time. I'll try it now again

thin locust
#

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.

limpid rampart
#

Solved!! Thanks once again Isaac

thin locust
#

You're welcome