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

Unit tests for character stamina functions #38936

Merged
merged 16 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/mods/TEST_DATA/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Test Data pseudo-mod #

This mod is purely for loading data to be used by `tests/cata_test`. It is
automatically loaded by `tests/test_main.cpp`, so any items, recipes, or other
content defined in the mod will be available to everything in `tests/`.

The benefit of using this mod for test data is that it allows a clean
separation of tests from in-game content. Instead of testing with content in
the main `data/json` directory, functional tests can use `TEST_DATA` content
to ensure a more stable and controllable set of example data.

20 changes: 20 additions & 0 deletions data/mods/TEST_DATA/metal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"id": "test_platinum_bit",
"type": "AMMO",
"category": "spare_parts",
"name": { "str": "TEST platinum bit" },
"description": "A soft shiny metal. Before the apocalypse this would've been worth a small fortune but now its value is greatly diminished.",
"weight": "1 g",
"//": "Density 21.45g/cm³ ~ 5.4kg/250ml @ stack 1000 = 5g/unit",
"volume": "10ml",
"price": 100000,
"price_postapoc": 100,
"count": 100,
"stack_size": 40,
"material": [ "platinum" ],
"symbol": "/",
"color": "light_gray",
"ammo_type": "components"
}
]
12 changes: 12 additions & 0 deletions data/mods/TEST_DATA/modinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"type": "MOD_INFO",
"ident": "test_data",
"name": "TESTING DATA",
"description": "Adds mockup items, recipes, and other content for use by automated tests.",
"category": "content",
"//": "Not really obsolete! Marked as such to prevent it from showing in the main list",
"obsolete": true,
"dependencies": [ "dda" ]
}
]
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6659,7 +6659,7 @@ float Character::stamina_move_cost_modifier() const
// Both walk and run speed drop to half their maximums as stamina approaches 0.
// Convert stamina to a float first to allow for decimal place carrying
float stamina_modifier = ( static_cast<float>( get_stamina() ) / get_stamina_max() + 1 ) / 2;
if( move_mode == CMM_RUN && get_stamina() > 0 ) {
if( move_mode == CMM_RUN && get_stamina() >= 0 ) {
// Rationale: Average running speed is 2x walking speed. (NOT sprinting)
stamina_modifier *= 2.0;
}
Expand Down
Loading