-
-
Notifications
You must be signed in to change notification settings - Fork 555
Fix grade-school #1837
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
Fix grade-school #1837
Conversation
@wolf99 In the JavaScript track someone suggested an additional (or changed) test case for this exercise: exercism/javascript#1337 Could you maybe have look whether that could be covered with your new system and whether you want to include that case? |
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.
As of this time, here is what my review has covered:
- I see that the description.md, metadata.toml, and metadata.yml are exactly the same as the existing ones of grade-school.
- The proposed API given by
add
,roster
, andgrade
are agreeable to me. - The test cases' correctness, about which I have things to say. The verifier used is at https://github.com/petertseng/exercism-problem-specifications/blob/grade1837-ver/exercises/grade-school2/verify.rb and will be updated if any significant changes to the API are implemented.
Here are things I have no opinion on, and so review of that is left to others (I will not review these things):
- The mechanism by which grade-school should be replaced, if at all.
Here is something that I think should be a necessary component of this: It should be clearly specified in the description that we are not allowing two students to have the same name. Here are some other cases you might consider. I consider these optional; I would still approve a correct PR that does not contain these cases.
|
Reading #1824, the main problem mentioned was that the duplicate add behaviour was not well-specified. You also mention:
What other issues are you referring to? |
Thanks for the comments all. @petertseng I will update these now. The metadata etc are the same as grade-school as the intention is to specify the same problem, but in such a way as it can be solved without logical inconsistencies. @junedev I will make up a commit to add this shortly @ErikSchierboom I was being a bit enthusiastic there I think. Main thing is to resolve the logical inconsistency in #1763 and #1824. #1819 was intended to resolve #1763, but I felt it wasn't the best solution to the issue. |
I'm having a hard time figuring out what exactly changed :) The issue was with the add method, right? And the fix was to return a boolean indicating if the value could be added? |
I have confirmed that the new JSON file has no problems with test cases correctness. If there are other considerations, they will be reviewed separately.
Hi @ErikSchierboom , |
My new commit just now should, I hope, add the test cases suggested by @petertseng and @junedev |
The review comment from @petertseng here: #1837 (comment) made me notice that this test case does not fully test what was intended. In the test case referred to in the comment, the intention is to ensure that James is not added to two grades. Any thoughts? |
Indeed, not with what we currently have. The way that fits in most naturally with the existing schema may simply be to have another case with the same inputs and different |
With the risk of sounding dumb: was the old exercise unsalvageable? As in: couldn't we reimplement some test cases and add new ones with proper behavior? |
Raw data supporting the above statement: The verifier for grade-school2 gets the correct result on all[1] grade-school cases without modification to either the cases or the verifier. [1]: excludes the one reimplemented grade-school case
Based on these above statements about |
TBH, I find it very hard to keep track of whats going on in a canonical-data.json when there are more than one or two test cases have However, if you think it better to continue in the original |
I was under the impression the two version are not compatible. But if they are, then I would vote for salvaging the existing exercise even if that means just adding another "re-implements" thingy for all test cases. As far as I know there is no (semi-automated) way to signal to all tracks that have the old version "this exercise is deprecated, implement this new exercise instead" so the chances the tracks apply the fixes is probably higher when they can re-sync the existing exercise instead (even if they need to adjust the code a bit). |
Thanks for the hard work! |
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.
items reviewed: All test cases are correct. API addition implied by add
is sensible and agreeable. API changes (if any) implied by changes to roster
and grade
are not only sensible, they are compatible with previous. Wherever I looked at an individual case and could think of an additional case that could be added, I suggested it.
items I did not review (if someone else cares about them, that interested individual must review these items themselves): I mentioned I looked at individual cases and considered whether to add any cases. I did not look at the overall suite to see if there's a group of cases that might be missing. So I only looked at the trees and not the forest.
changes suggested: None are required. Two in-line items, one optional and one highly suggested. Two more highly suggested:
highly suggested: For a commit history that makes it easy to see what changed in this PR, please amend commits so that this PR ends up with two commits: one commit that reindents the existing file with no other changes, and one commit that applies all other changes (add cases, change descriptions). When merging, these commits must not be squashed. If you don't want to do this but do want me to do it, I will.
highly suggested: the description.md for this problem should describe what happens when a student is added twice. The existing note that "Note that all our students only have one name." does not cover this, since that sentence is saying that the students are only referred to by a given name and not a family name/surname.
appendix: the diff required of the verifier was relatively small.
diff --git a/exercises/grade-school/verify.rb b/exercises/grade-school/verify.rb
index 1a51d52f..b2c83ec6 100644
--- a/exercises/grade-school/verify.rb
+++ b/exercises/grade-school/verify.rb
@@ -1,9 +1,15 @@
require 'json'
+require 'set'
require_relative '../../verify'
json = JSON.parse(File.read(File.join(__dir__, 'canonical-data.json')))
-cases = by_property(json['cases'], %w(roster grade))
+cases = by_property(json['cases'], %w(add roster grade))
+
+verify(cases['add'], property: 'add') { |i, _|
+ taken_names = Set.new
+ i['students'].map { |name, _| !!taken_names.add?(name) }
+}
reimplemented, not_reimplemented = cases['roster'].partition { |c| c['uuid'] == 'c125dab7-2a53-492f-a99a-56ad511940d8' }
@@ -16,5 +22,5 @@ verify(not_reimplemented, property: 'roster') { |i, c|
}
verify(cases['grade'], property: 'grade') { |i, _|
- (i['students'].group_by(&:last)[i['desiredGrade']] || []).map(&:first).sort
+ (i['students'].uniq(&:first).group_by(&:last)[i['desiredGrade']] || []).map(&:first).sort
}
"input": { | ||
"students": [["Blair", 2], ["James", 2], ["James", 2], ["Paul", 2]] | ||
}, | ||
"expected": [true, true, false, true] |
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.
I accept, as it fits one of the things I saw as a requirement: Must have one case that has an expected false
followed by expected true
.
optional: Might it seem like a smaller logical leap for the student to implement this if there were a case before this one that just adds James twice (expect true, false)? That way the expectation is isolated and hopefully isolated makes easy to understand.
e2b89ee
to
e005bb9
Compare
Thanks for the reviews! I have added the missing test suggested by Peter and added another line to the I have also split the indent correction to its own commit and squashed all other commits. I have not added the additional optional test Peter has suggested for two reasons:
Neither of these are very strong reasons, if anyone has a good suggestion for 2, I could overlook 1. |
Fixes #1824 Co-authored-by: Erik Schierboom <[email protected]>
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.
All changes I want have been done. I have nothing more to say.
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.
Yes, these tests now reflect the behaviour I would expect. Thank you.
Thanks @wolf99! |
Example implementation here: exercism/c#683
Fixes #1824
Wasn't sure how to replace the existing
grade-school
exercise so have just usedgrade-school2
(should this begrade-school-2
?) as had been suggested in slack (https://exercism-team.slack.com/archives/CARRG4MNC/p1628017550027100?thread_ts=1627502454.403900&cid=CARRG4MNC)If accepted the intention is that the existing
grade-school
should be deprecated as the spec is too problematic.I can add that as part of this PR if there is an agreed method?