-
Notifications
You must be signed in to change notification settings - Fork 40
Add animation unit tests #143
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
base: main
Are you sure you want to change the base?
Add animation unit tests #143
Conversation
rory-cd
left a comment
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.
General Information
Type of Change:
- New unit tests
This PR is a valuable addition, with unit tests covering a wide range of animation functions. Some assertions could be strengthened slightly, as noted with inline comments.
Optional: For consistency with other tests, change all occurrences of std::string to string, and add #include "types.h"
Code Quality
- Repository: This Pull Request is made to the correct repository
- Readability: The code is easy to read and follow
- Maintainability: The code could be easily maintained or extended in the future
Functionality
- Correctness: The code meets the requirements of the task
- Impact on Existing Functionality: The impact on existing functionality been considered
Testing
- Test Coverage: Unit tests provided for new or modified code
- Test Results: All tests passed
Documentation
- Documentation: Applicable internal documentation is updated and clear
Pull Request Details
- PR Description: The problem being solved is clearly described
- Checklist Completion: All relevant checklist items have been reviewed and completed
| * | ||
| * Tests for animation script and animation functions in SplashKit. | ||
| * Covers loading, creation, updating, and lifecycle of animations. |
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.
Optional: Remove these lines for consistency - other unit tests do not contain a description.
| SECTION("can get animation count") | ||
| { | ||
| int count = animation_count(script); | ||
| REQUIRE(count > 0); |
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.
To make this assertion more robust, it could be more specific, e.g. REQUIRE(count == 14);
| int idx = animation_index(script, "WalkFront"); | ||
| REQUIRE(idx >= 0); |
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.
To make this assertion more robust, it could be more specific, for example:
int idx = animation_index(script, "Dance");
REQUIRE(idx == 8);| SECTION("can get current cell") | ||
| { | ||
| int cell = animation_current_cell(anim); | ||
| REQUIRE(cell >= 0); |
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.
To make this assertion more robust, it could be more specific, e.g. REQUIRE(cell == 0);
| SECTION("can get frame time") | ||
| { | ||
| float frame_time = animation_frame_time(anim); | ||
| REQUIRE(frame_time >= 0.0f); |
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.
To make this section more robust, it could have an additional assertion, e.g. REQUIRE(frame_time <= 12.0f);. This would place an upper bound on the frame time.
|
|
||
| float time_after = animation_frame_time(anim); | ||
| REQUIRE(time_after == 0.0f); | ||
| REQUIRE_FALSE(animation_ended(anim)); |
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 could add another assertion to strengthen the test here, for example REQUIRE(animation_current_cell(anim) == 0);
| update_animation(anim); | ||
| } | ||
|
|
||
| float time_before = animation_frame_time(anim); |
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.
time_before is never used. It should be utilised or removed.
| update_animation(anim, 0.5f); | ||
|
|
||
| float frame_time = animation_frame_time(anim); | ||
| REQUIRE(frame_time > 0.0f); |
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.
If the frame has a frame_time of 0, this assertion will fail. Consider >= rather than >.
This would also benefit from an upper bound, e.g. REQUIRE(frame_time <= 12.0f);
| REQUIRE(anim != nullptr); | ||
|
|
||
| int dance_idx = animation_index(script, "Dance"); | ||
| assign_animation(anim, dance_idx); |
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.
There is no assertion here to test the function. This could be REQUIRE(animation_name(anim) == "dance"); or similar.
| SECTION("animation_name returns empty for null") | ||
| { | ||
| disable_logging(WARNING); | ||
| REQUIRE(animation_name(nullptr) == ""); |
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.
This could be REQUIRE(animation_name(nullptr).empty()); for consistency with earlier usage of empty strings (line 190).
Description
Adds comprehensive automated unit tests for animation functions in SplashKit. The existing
test_animation.cppprovides manual/interactive testing, but lacked automated unit tests that can be run as part of CI/CD pipelines.This PR adds
unit_test_animation.cppwhich provides automated tests for:Animation Script functions:
load_animation_script,free_animation_script,free_all_animation_scriptshas_animation_script,animation_script_named,animation_script_nameanimation_count,has_animation_named,animation_indexAnimation functions:
create_animation(multiple overloads with/without sound)free_animation,assign_animation(multiple overloads)animation_name,animation_current_cell,animation_endedanimation_entered_frame,animation_frame_time,animation_current_vectorupdate_animation,restart_animationEdge case handling:
The tests use the existing
kermit.txtanimation script resource and follow the same patterns as other unit tests in the project.Type of change
How Has This Been Tested?
Built the test project using CMake as per build instructions. All tests pass successfully.
Automated Testing:
Testing Checklist
Checklist