Skip to content

Fixes #714 assertTrue -> assertEquals#750

Merged
Smarticles101 merged 4 commits into
exercism:masterfrom
matthewstyler:master
Aug 23, 2017
Merged

Fixes #714 assertTrue -> assertEquals#750
Smarticles101 merged 4 commits into
exercism:masterfrom
matthewstyler:master

Conversation

@matthewstyler
Copy link
Copy Markdown
Contributor


Reviewer Resources:

Track Policies

@matthewstyler
Copy link
Copy Markdown
Contributor Author

tests failing, will investigate

@stkent
Copy link
Copy Markdown
Contributor

stkent commented Aug 21, 2017

I think #714 is invalid; there's a deliberate use of a custom equals method there. From the GridPosition starter class:

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

}

@stkent
Copy link
Copy Markdown
Contributor

stkent commented Aug 21, 2017

We could instead provide a full equals implementation, just need to be wary of the fact that it'll be visible to implementors.

@Smarticles101
Copy link
Copy Markdown
Member

Smarticles101 commented Aug 21, 2017

So then is the assertEquals method using the generic equals method from java.lang.Object? @stkent

@stkent
Copy link
Copy Markdown
Contributor

stkent commented Aug 22, 2017

Yep, exactly, hence the failures!

@matthewstyler
Copy link
Copy Markdown
Contributor Author

matthewstyler commented Aug 22, 2017

My vote would be for an overridden equals, the class only exists to track the position

@FridaTveit
Copy link
Copy Markdown
Contributor

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

@matthewstyler
Copy link
Copy Markdown
Contributor Author

ya, no problem @FridaTveit

Copy link
Copy Markdown
Contributor

@FridaTveit FridaTveit left a comment

Choose a reason for hiding this comment

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

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
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.

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

@Smarticles101
Copy link
Copy Markdown
Member

Thanks for taking the time to do all this @matthewstyler I think it looks good now

@Smarticles101 Smarticles101 merged commit ef869fd into exercism:master Aug 23, 2017
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.

4 participants