Skip to content

Commit

Permalink
tests: Count how many turns you can run
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed Dec 20, 2021
1 parent 8c3d3dc commit 89b54b6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/cardio_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
// - Good health vs. poor health
// - Running N tiles before getting winded

static const efftype_id effect_winded( "winded" );

static const move_mode_id move_mode_crouch( "crouch" );
static const move_mode_id move_mode_run( "run" );
static const move_mode_id move_mode_walk( "walk" );

static const skill_id skill_swimming( "swimming" );

// Base BMR for default character
Expand All @@ -35,6 +41,23 @@ static void verify_default_cardio_options()
REQUIRE( cardiofit_stamina_scaling == 3 );
}

// Count how many turns of running it takes for character to run out of stamina or become winded
static int running_turns( Character &they )
{
// Take a deep breath and start running
they.set_stamina( they.get_stamina_max() );
they.set_movement_mode( move_mode_run );
int turns = 0;
int STOP = 1000; // Safe exit in case of Superman
while( they.get_stamina() > 0 && !they.has_effect( effect_winded ) ) {
++turns;
they.burn_move_stamina( to_moves<int>( 1_turns ) );
they.update_body();
REQUIRE( turns < STOP );
}
return turns;
}

// Cardio Fitness
// --------------
// The hidden "Cardio Fitness" stat returned by Character::get_cardiofit() is the main factor in
Expand Down Expand Up @@ -75,6 +98,7 @@ TEST_CASE( "traits affecting cardio fitness level", "[cardio][fitness][traits]"
GIVEN( "Languorous (BADCARDIO) trait" ) {
set_single_trait( they, "BADCARDIO" );
REQUIRE( they.base_bmr() == base_bmr );

THEN( "cardio is reduced" ) {
const int expect_cardio = 0.75 * base_bmr;
CHECK( they.get_cardiofit() == Approx( expect_cardio ).margin( 2 ) );
Expand All @@ -83,22 +107,30 @@ TEST_CASE( "traits affecting cardio fitness level", "[cardio][fitness][traits]"
// Original stamina_max with mutation multiplier
//CHECK( they.get_stamina_max() == 6535 ); // 8714 * 0.75
}
THEN( "they can run for 49 turns" ) {
CHECK( running_turns( they ) == 49 );
}
}

// No cardio mutations - default avatar
GIVEN( "no cardio mutations or traits" ) {
clear_avatar();
REQUIRE( they.base_bmr() == base_bmr );

THEN( "cardio is normal" ) {
CHECK( they.get_cardiofit() == base_bmr );
CHECK( they.get_stamina_max() == base_stamina );
}
THEN( "they can run for 58 turns" ) {
CHECK( running_turns( they ) == 58 );
}
}

// cardio_multiplier = 1.25
GIVEN( "Indefatigable (GOODCARDIO) trait" ) {
set_single_trait( they, "GOODCARDIO" );
REQUIRE( they.base_bmr() == base_bmr );

THEN( "cardio is increased" ) {
const int expect_cardio = 1.25 * base_bmr;
CHECK( they.get_cardiofit() == Approx( expect_cardio ).margin( 2 ) );
Expand All @@ -107,12 +139,16 @@ TEST_CASE( "traits affecting cardio fitness level", "[cardio][fitness][traits]"
// Original stamina_max with mutation multiplier
//CHECK( they.get_stamina_max() == 10892 ); // 8714 * 1.25
}
THEN( "they can run for 66 turns" ) {
CHECK( running_turns( they ) == 66 );
}
}

// cardio_multiplier = 1.4
GIVEN( "Hyperactive (GOODCARDIO2) trait" ) {
set_single_trait( they, "GOODCARDIO2" );
REQUIRE( they.base_bmr() == base_bmr );

THEN( "cardio is increased more" ) {
const int expect_cardio = 1.4 * base_bmr;
CHECK( they.get_cardiofit() == Approx( expect_cardio ).margin( 2 ) );
Expand All @@ -121,6 +157,9 @@ TEST_CASE( "traits affecting cardio fitness level", "[cardio][fitness][traits]"
// Original stamina_max with mutation multiplier
//CHECK( they.get_stamina_max() == 12199 ); // 8714 * 1.4
}
THEN( "they can run for 72 turns" ) {
CHECK( running_turns( they ) == 72 );
}
}
}

Expand Down

0 comments on commit 89b54b6

Please sign in to comment.