Repository navigation
Update grade-school tests and reference implementation to 1.0.0 (#1538) - #1572
Conversation
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking great, thanks for tackling this issue @alis0nc! 🙂
I've left a few comments, let me know if you have any questions and feel free to leave comments if you disagree with any of my suggestions 🙂
|
|
||
| /* | ||
| * Based on problem-specifications/exercises/grade-school/canonical-data.json 1.0.0 | ||
| */ |
There was a problem hiding this comment.
This comment isn't needed as we have the version file to tell us which version of the canonical data the tests implement 🙂
There was a problem hiding this comment.
Thats fair. I included it because I had seen it in a Python or c# test, I believe, but I don't think that one had the .meta directory with the version file.
There was a problem hiding this comment.
I see! Yes, we used to use them as well before we had the version files 🙂
| } | ||
|
|
||
| @Test | ||
| public void startsWithNoStudents() { |
There was a problem hiding this comment.
This test isn't in the canonical data as far as I can tell so we should remove it from our tests 🙂
There was a problem hiding this comment.
Fair point. I've removed the test, since it isn't in the canonical data
| School school = new School(); | ||
| school.add("Aimee", 2); | ||
| assertThat(school.grade(2), hasItem("Aimee")); | ||
| String[] expected = {"Aimee"}; |
There was a problem hiding this comment.
I think it might be easier to create a list and compare that? 🙂
There was a problem hiding this comment.
looking a bit more into this, I'm gonna change all the tests to have a List<String> expected and use assertThat and ham crest's is to compare expected and actual. That seems more idiomatic than doing a list->array conversion on the actual value.
| @@ -25,14 +33,14 @@ List<String> fetchGradeFromDatabase(int grade) { | |||
| if (!database.containsKey(grade)) { | |||
There was a problem hiding this comment.
I think this method can be private? 🙂
There was a problem hiding this comment.
sounds good to me. I think it's somewhere in the standards, too, that reference solutions should be idiomatic, and that includes access idioms :)
| return database.get(grade); | ||
| } | ||
|
|
||
| Map<Integer, List<String>> studentsByGradeAlphabetical() { |
There was a problem hiding this comment.
I think this method can be private? 🙂
There was a problem hiding this comment.
Above comment applies here too :)
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great, thanks for making those changes @alis0nc! 🙂
I've left a few suggestions but they're all minor things so it's up to you if you want to do them as part of this PR or if you'd rather I open a new issue for it 🙂
| * Based on problem-specifications/exercises/grade-school/canonical-data.json 1.0.0 | ||
| */ | ||
| public class SchoolTest { | ||
| School school; |
There was a problem hiding this comment.
This should be private 🙂
There was a problem hiding this comment.
I'll make this change as part of this PR, and leave the others for another one
| String[] expected = {"Aimee"}; | ||
| assertArrayEquals(expected, school.roster().toArray(new String[0])); | ||
| List<String> expected = Arrays.asList("Aimee"); | ||
| assertThat(school.roster(), is(expected)); |
There was a problem hiding this comment.
A couple of minor things here:
- Since you're creating a list with a single element you can use
Collections.singletonList - You should be able to use
assertEqualsinstead ofassertThat. That would be more consistent with our other tests. I know that's not something you've introduced to these tests, just a minor thing that I noticed now 🙂
Those are both minor things though so I'm happy merging this PR without those changes 🙂 Let me know if you do want to do them as part of this PR, otherwise I'll open a new issue for it 🙂
| String[] expected = {}; | ||
| assertArrayEquals(expected, school.roster().toArray(new String[0])); | ||
| school = new School(); | ||
| List<String> expected = Arrays.asList(); |
There was a problem hiding this comment.
Again a very minor thing: you can use Collections.emptyList here 🙂
FridaTveit
left a comment
There was a problem hiding this comment.
Great, thanks @alis0nc! 🙂
Update grade-school tests and reference implementation to 1.0.0, as mentioned in #1538
Reviewer Resources:
Track Policies