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 tests for character biometrics (BMI, BMR, weight, kcal) #39266

Merged
merged 9 commits into from
Apr 6, 2020

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented Apr 4, 2020

Summary

SUMMARY: Infrastructure "Add tests for character BMI / kcal / weight"

Purpose of change

To improve test coverage of character health stats

Describe the solution

Adds a few test cases covering behavior of low-level health-related functions including:

  • Character::get_bmi()
  • Character::get_kcal_percent()
  • Character::get_max_healthy()
  • Character::get_weight_string()
  • Character::height()
  • Character::bodyweight()
  • Character::metabolic_rate_base()
  • Charactrer::get_bmr()

Test cases check the following:

  • Body mass index
    • Descriptive strings (Emaciated, Underweight, Normal, Overweight, Obese etc.)
    • Correspondence between BMI and stored kcals
  • Maximum "hidden health" value
    • +200 for normal weight range
    • -200 for "very obese" and larger
    • Range of values in between
  • Heights and bodyweights for mutation-related body sizes
    • Normal: 175cm, 49-107kg
    • Small: 125cm, 25-55kg
    • Large: 225cm, 81-177kg
    • Huge: 275cm, 121-265kg
  • Activity levels
    • Stored as floating-point but only uses discrete values from game constants
    • Reset, increase, decrease adjusts between levels
  • Metabolic base rate
    • 1.0 default based on game_balance.json
    • Mutations add/subtract, ex. "Rapid metabolism" is higher, "Cold blooded" lower
  • Basal metabolic rate (BMR)
    • e.g. 2087 kcal for normal size character at BMI 25.0, at rest (not exercising)
    • Checks NO_EXERCISE, MODERATE_EXERCISE, EXTRA_EXERCISE
    • Checks normal, small, large body sizes
    • Checks normal, very fast, and cold-blooded metabolisms

Describe alternatives you've considered

Would eventually like to add some tests of the healthy and healthy_mod character attributes, and their effects on healing rate, resistance to disease, mending broken limbs and so forth.

Testing

Using tests/cata_test [biometrics]

Additional context

7 new test cases, 351 assertions, runs in 0.001 sec

image

Note: These tests only check current behavior of the game code; whether that behavior is truly realistic and desirable is outside the scope of this PR, and I did not do more than superficial research on these formulas. Running these same BMR tests against the revised calculations in #36862 gives different results which may actually be more correct in terms of realism. If so, these tests should be easy to adjust.

@wapcaplet
Copy link
Contributor Author

Travis-CI failure in unrelated test:

creature_test.cpp:54: FAILED:
  CHECK_THAT( weight.second, IsBinomialObservation( num_tests, expected_proportion ) )
with expansion:
  3964 (0xf7c) is from Bin(15000, 0.25) [3543.65 <= obs <= 3956.35]
with messages:
  hit roll = 1
  left leg

@KorGgenT KorGgenT added Code: Tests Measurement, self-control, statistics, balancing. Mechanics: Character / Player Character / Player mechanics labels Apr 5, 2020
@wapcaplet wapcaplet changed the title Add tests for character BMI / kcal / weight WIP Add tests for character biometrics (BMI / kcal / weight / BMR) Apr 5, 2020
@wapcaplet wapcaplet changed the title WIP Add tests for character biometrics (BMI / kcal / weight / BMR) WIP Add tests for character biometrics (BMI, BMR, weight, kcal) Apr 5, 2020
@wapcaplet
Copy link
Contributor Author

On further consideration, we could use more coverage on related biometrics functions like height(), bodyweight(), get_bmr() and such, so I am setting this back to WIP to add these as well.

 Plus stub test cases for BMR and activity level
Plus a nice confirmation from Wikipedia on the accuracy of our
`max_healthy` tests in relation to BMI
@wapcaplet wapcaplet changed the title WIP Add tests for character biometrics (BMI, BMR, weight, kcal) Add tests for character biometrics (BMI, BMR, weight, kcal) Apr 5, 2020
@kevingranade kevingranade merged commit bfae818 into CleverRaven:master Apr 6, 2020
@wapcaplet wapcaplet deleted the char-bmi-tests branch April 12, 2020 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code: Tests Measurement, self-control, statistics, balancing. Mechanics: Character / Player Character / Player mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants