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

Refactored test code smells #397

Merged
merged 44 commits into from
May 10, 2021

Conversation

niels89
Copy link
Contributor

@niels89 niels89 commented May 3, 2021

Refactored test code smells to improve test code quality.

niels89 and others added 30 commits May 3, 2021 21:17
…in Unit Tests for EntityAction and EntityActionMap. Removes eagerness, assertion roulette and indirect testing.
…parate unit tests, eliminating eager tests and assertion roulette.
…t tests for the overloads, removing eager tests and reducing duplication
// TODO: target collision box wrongfully detects an intersection with blocking collision box due to floating point precision miscalculation
// within method GeometricUtilities.intersects - intersection is marginally positive in case of left movement, but marginally negative in right movement
// Game.physics().move(ent, 315, MOVE_10X10Y_DISTANCE);
Game.physics().move(ent, 315, MOVE_10X10Y_DISTANCE-(1e-14));
Copy link
Contributor

Choose a reason for hiding this comment

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

@nightm4re94 @Gamebuster19901 During development we found this issue with floating point precision during calculating collisions and intersections.
Basically the test will fail if I provide the constant as it is, but it will pass if I subtract a marginal value. The issue is that due to the floating point precision it miscalculates an intersection to exist where there should not be any...
How should we handle this problem?

Copy link
Member

Choose a reason for hiding this comment

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

is 1e-14 the order of magnitude of the difference in this example?
I think it's odd that a number as small as 0.00000000000001 has an effect on the floating number equality assertion, as we've defined the tolerance threshold EPSILON = 1e-6 = 0.000001.

Copy link
Contributor

@jluech jluech May 4, 2021

Choose a reason for hiding this comment

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

Exactly my point. However, the problem is not the threshold of EPSILON (since it is only relevant for the assertion), but lies in the underlying computations within GeometricUtilities.intersects(). The small delta seems to trigger a floating point change that results in finding an intersection between the two CollisionBoxes when they really just touch instead of intersect. As a result, the movement is handled differently and the target position is off the expectation

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see! Thanks for clarifying!

Copy link
Contributor

Choose a reason for hiding this comment

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

to come back to the original question: how should we proceed with this?
Do you guys work with the Github Issues as backlog (i.e., should we open an issue and ignore the problem for now in this PR), or should we include a potentially larger refactoring in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

I think this would best be tracked separately - feel free to open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

created an issue here

@Gamebuster19901

This comment has been minimized.

@nightm4re94

This comment has been minimized.

@Gamebuster19901

This comment has been minimized.

@nightm4re94

This comment has been minimized.

@niels89
Copy link
Contributor Author

niels89 commented May 7, 2021

I think it would probably make sense to integrate #398 first, then it is simpler to fix the conflicts of this one (both changed EntityTests)

@niels89
Copy link
Contributor Author

niels89 commented May 8, 2021

Resolved the conflicts for ArrayUtilitiesTests, EntityTests and GeometricUtilitiesTests.

@jluech
Copy link
Contributor

jluech commented May 10, 2021

That absolutely makes sense and I agree! Didn't get that before, sorry.

I locally switched the methods to use GeometricUtilities.intersects((Rectangle2D) shapeA, (Rectangle2D) shapeB) instead. Unfortunately, no tests suddenly fail, so there is no programmatic way to be sure this is the right change. Are you guys sure about that? I can push it if you want me to.

@Gamebuster19901
Copy link
Contributor

Gamebuster19901 commented May 10, 2021

That absolutely makes sense and I agree! Didn't get that before, sorry.

I locally switched the methods to use GeometricUtilities.intersects((Rectangle2D) shapeA, (Rectangle2D) shapeB) instead. Unfortunately, no tests suddenly fail, so there is no programmatic way to be sure this is the right change. Are you guys sure about that? I can push it if you want me to.

Not sure what you mean, the physics already only uses GeometricUtilities.intersects((Rectangle2D) shapeA, (Rectangle2D) shapeB).

Basically shapeIntersects(final Shape shapeA, final Shape shapeB) is currently unused, however someone could invoke that method directly and it seems like would calculate physics differently than what the normal physics if you pass in Rectangle2Ds. It was something I noticed but isn't really related to this PR atm.

@jluech
Copy link
Contributor

jluech commented May 10, 2021

I locally switched the methods to use GeometricUtilities.intersects((Rectangle2D) shapeA, (Rectangle2D) shapeB) instead. Unfortunately, no tests suddenly fail, so there is no programmatic way to be sure this is the right change. Are you guys sure about that? I can push it if you want me to.

Not sure what you mean, the physics already only uses GeometricUtilities.intersects((Rectangle2D) shapeA, (Rectangle2D) shapeB).

Basically shapeIntersects(final Shape shapeA, final Shape shapeB) is currently unused, however someone could invoke that method directly and it seems like would calculate physics differently than what the normal physics if you pass in Rectangle2Ds. It was something I noticed but isn't really related to this PR atm.

Okay, then I will ignore it for now. I was mostly irritated that no tests would fail when exchanging methods (if you say it should return something different). But this is most likely due to not properly covering this method in general, which is what we are currently trying to fix ^^ point noted, will probably try to address that in the upcoming changes we plan 👍

=> PR should now be free of open issues and conflicts

Copy link
Member

@nightm4re94 nightm4re94 left a comment

Choose a reason for hiding this comment

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

Beautiful! Thank you for your efforts.

@nightm4re94 nightm4re94 merged commit 5c20ffa into gurkenlabs:master May 10, 2021
nightm4re94 pushed a commit that referenced this pull request Jun 8, 2021
* refactor: move tests to correct package

* refactor: fix test param supply docs links

* feat: specifically treat line intersection and add tests

* refactor: use GeoUtils:intersects for rectangles

* Implemented unit test for PhysicsEngine::raycast(Line2D, Collision, ICollisionEntity)

* Implemented unit test for PhysicsEngine constructor

* Implemented further unit tests for PhysicsEngine::raycast() overloads

* Implemented unit tests for PhysicsEngine::raycast overloads

* Implemented additional unit tests for GuiComponent::getTweenValues and setTweenValues

* Implemented unit test for GuiComponent::getTextToRender

* Implemented unit test for GuiComponent::getShape

* Implemented unit tests two overloads of SpeechBubble::create

* Added null assertion to PhysicsEngineTests::testRaycastCollision

* Refactor FileUtilitiesTests code

* Slight adjustment of PhysicsEngineTests

* Improved variable names in PhysicsEngineTests

* Add test cases for deleteDir and findFilesByExtension

* Remove unused imports

* fix: fix flaky test checking for array order in unordered array

* refactor: restructure test file

* Refactor test cases for FileUtilities

* refactor: integrate ParticleTests in correct package

Co-authored-by: Niels Kübler <niels.kuebler@uzh.ch>
Co-authored-by: ddreimane <dreimane.dace@gmail.com>
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.

None yet

5 participants