-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Unit tests for character stamina functions #38936
Merged
Merged
Conversation
This file contains 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
wapcaplet
changed the title
Unit tests for character stamina functions
[WIP] Unit tests for character stamina functions
Mar 21, 2020
Unexpected failure for running speed at zero stamina; speed drops to 0.5 instead of the expected 1.0
Using `get_stamina() > 0` in the `src/character.cpp` condition for running causes a discontinuity in return value, where the running cost modifier drops sharply from: stamina 0.001 => cost modifier 1.001 stamina 0.000 => cost modifier 0.500 Making this condition `>= 0` eliminates the discontinuity: stamina 0.001 => cost modifier 1.001 stamina 0.000 => cost modifier 1.000
Since the DEBUG_STORAGE mutation gives the character many billions of metric tonnes of weight capacity, it was making it difficult to test being overburdened for stamina (no backpack is big enough, nor any material in the game dense enough, to make such a character overburdened). So now it's a parameter to the helper function, defaulting to true.
Also force-remove "winded" status in helper functions to ensure `can_run()` succeeds.
wapcaplet
force-pushed
the
stamina-tests
branch
from
March 22, 2020 04:38
41551ee
to
a311c39
Compare
Stub in a `data/mods/TEST_DATA` folder for fake/mockup test items and other non-game data for use by test cases.
By using tin powder at increments of 2g, some tests were failing because player capacity could not be exactly reached with 2g increments. Cross-compilation on minGW (according to Travis CI) seems even more susceptible to this, leading to some tests giving more off-by-1 results there than they do on my Ubuntu box. There appear to be no high-density, stackable in-game items with a unit size of only 1g, so I created a new `test_platinum_bit` in the `TEST_DATA` mod folder, and used it in the `burden_player` helper instead of 2g tin powder.
wapcaplet
changed the title
[WIP] Unit tests for character stamina functions
Unit tests for character stamina functions
Mar 22, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SUMMARY: Infrastructure "Unit tests for character stamina functions"
Purpose of change
To ensure the behavior of the lower-level character stamina functions are well-understood, documented, and automatically tested.
Describe the solution
Adds test cases exercising behaviors of these functions:
Character::stamina_move_cost_modifier
Character::burn_move_stamina
Character::mod_stamina
Character::update_stamina
Test cases cover the following:
stamina_move_cost_modifier
)mod_stamina
)burn_move_stamina
)burn_move_stamina
)update_stamina
)update_stamina
)update_stamina
)Depends (only a tiny bit) on #38926
Depends on #38945 for test data
Describe alternatives you've considered
Leaving the spoilers unspoiled
Testing
make && tests/cata_test [stamina]
Additional context
Total of 7 new test cases with 343 assertions, running in 0.002 seconds:
Regarding the regression test for #38877 , to be perfectly honest this entire PR was driven by my desire to test that aspect of stamina regeneration better - from my first commit testing the curious scaling function
stamina_move_cost_modifier
to the last, which aimed to expose the discrepancy between stamina regeneration rates in different movement modes.To that end, I tested by reverting the fix made in #38891 , and running the same tests. Quite a few of them failed (as expected), including those relating to movement mode, but a couple others indicate that stamina regen rate overall is decreased now, particularly at lower stamina levels, since the
stamina_move_cost_modifier
scaling function gives bigger buffs at lower stamina (and the test case checks regen rate starting with stamina only 10% full).For posterity, here's a condensed version of what those failures looked like before #38891
This confirms the overall stamina-nerfing that resulted from the PR, especially for crouching. I hope by having these tests outlined now, we will be in a better position to understand how stamina burn and regen works now, and make any necessary rebalances.