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

Add unit test for Node3D #97143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JayTropper
Copy link

This commit adds several test cases for the Node3D class for #43440.

The test consists of two basic test cases and nine test cases that cover several utility methods like look_at, rotate_object_local, to_localand more.

@JayTropper JayTropper requested a review from a team as a code owner September 18, 2024 12:06
tests/test_main.cpp Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member

AThousandShips commented Sep 18, 2024

The commit is associated with another user, you will need to reset the author with git commit --reset-author --amend, making sure you're logged in with the right account on your computer

tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member

If the tests still fail on the last build it will be because you generated your expected values on a non-doubles build, then you'll need to build a double precision build (or print the values in the test run) and update them, so they work in both cases (the double precision values will work for single precision)

tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
tests/scene/test_node_3d.h Outdated Show resolved Hide resolved
CHECK(test_node3->get_global_position().is_equal_approx(Vector3(200, 0, 110)));
CHECK(wrap_rotation_angles(test_node3->get_global_rotation_degrees()).is_equal_approx(Vector3(0, 180, 270)));
CHECK(test_node3->get_position().is_equal_approx(Vector3(0, 0, 10)));
CHECK(wrap_rotation_angles(test_node3->get_rotation_degrees()).is_equal_approx(Vector3(180, 0, 90)));
Copy link
Author

@JayTropper JayTropper Sep 20, 2024

Choose a reason for hiding this comment

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

Unfortunately, posmod(360) only works in the main cases and not in the corner case I have in this line of code (182).
The corner case: When executing with floats, the value of the y axes is -0.000009. When executing with doubles, the value of the y axes is 0.00000000000001. That means in the case of posmod(360) for double, no modulo is applied and the value stays the same. In the case of float precision, since it has a negative value, the value is adapted to 359,999991, which will lead to a failing test result since the test checks for 0. I hope that makes the situation clear.
We can leave it like that, or I could remove this case and take other values to avoid this corner case. Then there is no need for the wrap_rotation_angles() method since it only appears in this specific case.

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

Successfully merging this pull request may close these issues.

3 participants