Fixes #714 assertTrue -> assertEquals#750
Conversation
|
tests failing, will investigate |
|
I think #714 is invalid; there's a deliberate use of a custom class GridPosition {
final int x;
final int y;
GridPosition(final int x, final int y) {
this.x = x;
this.y = y;
}
/*
* This equals method is of deliberately narrow scope (only allows comparison with another GridPosition) to increase
* readability. In general, one should provide a full implementation of Object.equals(Object obj) and a
* corresponding implementation of Object.hashCode(). See
*
* https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
*
* and
*
* https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()
*
* for more information.
*/
boolean equals(final GridPosition gridPosition) {
return this.x == gridPosition.x && this.y == gridPosition.y;
}
} |
|
We could instead provide a full equals implementation, just need to be wary of the fact that it'll be visible to implementors. |
|
So then is the assertEquals method using the generic |
|
Yep, exactly, hence the failures! |
|
My vote would be for an overridden equals, the class only exists to track the position |
|
Sorry, that's my bad for not checking throroughly enough when creating the issue! I did check that the change worked locally, but only for some of the tests when the grid position didn't actually change. I agree, I think overriding equals would be the best plan :) Would you be happy doing that as part of this PR @matthewstyler? You absolutely don't have to, I'm happy to open a separate PR for it :) |
|
ya, no problem @FridaTveit |
FridaTveit
left a comment
There was a problem hiding this comment.
This looks great @matthewstyler! Thanks for putting the effort in to fix this :)
There's just one small formatting problem but apart from that it's good to go! :)
| boolean equals(final GridPosition gridPosition) { | ||
| return this.x == gridPosition.x && this.y == gridPosition.y; | ||
| } | ||
| @Override |
There was a problem hiding this comment.
The spacing seems to have gone a bit wrong here and in the test file. It should be indented with four spaces :) If you're using IntelliJ you can use ctrl + alt + L to automatically format the code (cmd + alt + L on a mac). That should fix spacing issues in the current file and will even remove unused imports if you tell it to in the reformat code dialog box (see https://www.jetbrains.com/help/idea/reformatting-source-code.html). On eclipse it's ctrl + shift + F :)
|
Thanks for taking the time to do all this @matthewstyler I think it looks good now |
Reviewer Resources:
Track Policies