Skip to content
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 test failure on TestPoint#testEqualsAndHashCode #13433

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

easyice
Copy link
Contributor

@easyice easyice commented May 29, 2024

If two objects are different, it might have the same hashcode. in this case, Point(-180.0,90.0) and Point(180.0,-90.0) will have the same hashcode value.

org.apache.lucene.geo.TestPoint > testEqualsAndHashCode FAILED
    java.lang.AssertionError: Values should be different. Actual: -1965031424
        at __randomizedtesting.SeedInfo.seed([ADA73B977A63C061:DE69C35A79C6BF50]:0)
        at org.junit.Assert.fail(Assert.java:89)
        at org.junit.Assert.failEquals(Assert.java:187)
        at org.junit.Assert.assertNotEquals(Assert.java:201)
        at org.junit.Assert.assertNotEquals(Assert.java:213)
        at org.apache.lucene.geo.TestPoint.testEqualsAndHashCode(TestPoint.java:59)
./gradlew :lucene:core:test --tests "org.apache.lucene.geo.TestPoint.testEqualsAndHashCode"  -Ptests.seed=ADA73B977A63C061

We had similar issues in the other tests like TestCircle#testEqualsAndHashCode, TestXYPolygon#testEqualsAndHashCode. it seems it also needs to be removed. for random values, the hash code must be different is a wrong assumption.

@easyice
Copy link
Contributor Author

easyice commented May 30, 2024

Maybe we don't need to fix the other tests right now, unless they really encounter hash collisions.

Copy link
Member

@mikemccand mikemccand left a comment

Choose a reason for hiding this comment

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

Thanks @easyice -- this is indeed the wrong assumption. Different (.equals() == false) objects are indeed allowed to have the same hash code.

@easyice
Copy link
Contributor Author

easyice commented Jun 3, 2024

Thanks for reviewing, Mike!

@easyice easyice merged commit a6f920d into apache:main Jun 3, 2024
3 checks passed
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