Skip to content

Update grade-school tests and reference implementation to 1.0.0 (#1538) - #1572

Merged
FridaTveit merged 3 commits into
exercism:masterfrom
alis0nc:1538-update-grade-school-to-1.0.0
Oct 3, 2018
Merged

FridaTveit merged 3 commits into
exercism:masterfrom
alis0nc:1538-update-grade-school-to-1.0.0

Conversation

@alis0nc

@alis0nc alis0nc commented Oct 1, 2018

Copy link
Copy Markdown
Contributor

Update grade-school tests and reference implementation to 1.0.0, as mentioned in #1538


Reviewer Resources:

Track Policies

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't needed as we have the version file to tell us which version of the canonical data the tests implement 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Yes, we used to use them as well before we had the version files 🙂

}

@Test
public void startsWithNoStudents() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't in the canonical data as far as I can tell so we should remove it from our tests 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be easier to create a list and compare that? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be private? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be private? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above comment applies here too :)

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 assertEquals instead of assertThat. 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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again a very minor thing: you can use Collections.emptyList here 🙂

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks @alis0nc! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants