generated from vortexntnu/vortex-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Add tests for C++ code and refactor python tests #3
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e333a8
C++ tests and refactor python tests
Andeshog 3f41d8e
merge main
Andeshog 2c0babf
update README
Andeshog 7f2887f
formatting
Andeshog b316553
add test for twist twist multiplication
Andeshog f29cf9b
add tests for ros conversion
Andeshog 7bc118e
add geometry_msgs dependency
Andeshog 7871d82
docs
Andeshog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <vortex_utils/cpp_utils.hpp> | ||
|
|
||
| namespace vortex_utils { | ||
|
|
||
| // Test that the value does not change when already in the interval [-pi, pi] | ||
| TEST(ssa, test_ssa_0) { | ||
| EXPECT_EQ(0, ssa(0)); | ||
| } | ||
|
|
||
| // Test that 2 pi correctly maps to 0 | ||
| TEST(ssa, test_ssa_2pi) { | ||
| EXPECT_EQ(0, ssa(2 * M_PI)); | ||
| } | ||
|
|
||
| // Test that values over pi gets mapped to the negative interval | ||
| TEST(ssa, test_ssa_3_5) { | ||
| EXPECT_NEAR(-2.78, ssa(3.5), 0.01); | ||
| } | ||
|
|
||
| // Test that values under -pi gets mapped to the positive interval | ||
| TEST(ssa, test_ssa_minus_3_5) { | ||
| EXPECT_NEAR(2.78, ssa(-3.5), 0.01); | ||
| } | ||
|
|
||
| // Test that the skew-symmetric matrix is correctly calculated | ||
| TEST(skew_symmetric, test_skew_symmetric) { | ||
| Eigen::Vector3d vector(1, 2, 3); | ||
| Eigen::Matrix3d expected; | ||
| expected << 0, -3, 2, 3, 0, -1, -2, 1, 0; | ||
|
|
||
| Eigen::Matrix3d result = skew_symmetric(vector); | ||
| EXPECT_EQ(expected, result); | ||
| } | ||
|
|
||
| // Test that the identity quaternion correctly maps to 0, 0, 0 | ||
| TEST(quat_to_euler, test_quat_to_euler_1) { | ||
| Eigen::Quaterniond q(1.0, 0.0, 0.0, 0.0); | ||
| Eigen::Vector3d expected(0.0, 0.0, 0.0); | ||
| Eigen::Vector3d result = quat_to_euler(q); | ||
| for (int i = 0; i < 3; ++i) { | ||
| EXPECT_NEAR(expected[i], result[i], 0.01); | ||
| } | ||
| } | ||
|
|
||
| // Test that only changing w and x in the quat only affects roll | ||
| TEST(quat_to_euler, test_quat_to_euler_2) { | ||
| Eigen::Quaterniond q2(0.707, 0.707, 0.0, 0.0); | ||
| Eigen::Vector3d expected2(1.57, 0.0, 0.0); | ||
| Eigen::Vector3d result2 = quat_to_euler(q2); | ||
| for (int i = 0; i < 3; ++i) { | ||
| EXPECT_NEAR(expected2[i], result2[i], 0.01); | ||
| } | ||
| } | ||
|
|
||
| // Test that only changing w and y in the quat only affects pitch | ||
| TEST(quat_to_euler, test_quat_to_euler_3) { | ||
| Eigen::Quaterniond q3(0.707, 0.0, 0.707, 0.0); | ||
| Eigen::Vector3d expected3(0.0, 1.57, 0.0); | ||
| Eigen::Vector3d result3 = quat_to_euler(q3); | ||
| for (int i = 0; i < 3; ++i) { | ||
| EXPECT_NEAR(expected3[i], result3[i], 0.01); | ||
| } | ||
| } | ||
|
|
||
| // Test that only changing w and z in the quat only affects yaw | ||
| TEST(quat_to_euler, test_quat_to_euler_4) { | ||
| Eigen::Quaterniond q4(0.707, 0.0, 0.0, 0.707); | ||
| Eigen::Vector3d expected4(0.0, 0.0, 1.57); | ||
| Eigen::Vector3d result4 = quat_to_euler(q4); | ||
| for (int i = 0; i < 3; ++i) { | ||
| EXPECT_NEAR(expected4[i], result4[i], 0.01); | ||
| } | ||
| } | ||
|
|
||
| TEST(quat_to_euler, test_quat_to_euler_5) { | ||
| Eigen::Quaterniond q5(0.770, 0.4207, -0.4207, -0.229); | ||
| Eigen::Vector3d expected5(1.0, -1.0, 0.0); | ||
| Eigen::Vector3d result5 = quat_to_euler(q5); | ||
| for (int i = 0; i < 3; ++i) { | ||
| EXPECT_NEAR(expected5[i], result5[i], 0.01); | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+74
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed a spot |
||
| } // namespace vortex_utils | ||
|
|
||
| int main(int argc, char** argv) { | ||
| testing::InitGoogleTest(&argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add documentation for each test explaining what you are testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what part is not "self documenting", or you feel needs documentation? I feel like docs here would just repeat what the code says 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a point but comments make the purpose of the test clearer, which is important if someone new were to look at the code later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can cook some comments then