Skip to content

Commit

Permalink
Update effective_food_volume_and_satiety test.
Browse files Browse the repository at this point in the history
  • Loading branch information
osuphobia committed Nov 28, 2024
1 parent 1f12753 commit 3a0dfeb
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions tests/comestible_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static const itype_id itype_marloss_seed( "marloss_seed" );

static const recipe_id recipe_veggy_wild_cooked( "veggy_wild_cooked" );

static const trait_id trait_GOURMAND( "GOURMAND" );

static const vitamin_id vitamin_mutagen( "mutagen" );
static const vitamin_id vitamin_mutagen_alpha( "mutagen_alpha" );
static const vitamin_id vitamin_mutagen_batrachian( "mutagen_batrachian" );
Expand Down Expand Up @@ -269,11 +271,13 @@ TEST_CASE( "cooked_veggies_get_correct_calorie_prediction", "[recipe]" )
//
// The Character::compute_calories_per_effective_volume function returns a dimensionless integer
// representing the "satiety" of the food, with higher numbers being more calorie-dense, and lower
// numbers being less so.
// numbers being less so. Water in food can be digested more quickly, but for a character with a
// bigger stomach, the difference will be smaller.
//
TEST_CASE( "effective_food_volume_and_satiety", "[character][food][satiety]" )
{
const Character &u = get_player_character();
Character &u = get_player_character();
u.unset_all_mutations();
double expect_ratio;

// Apple: 95 kcal / 200 g (1 serving)
Expand All @@ -283,9 +287,10 @@ TEST_CASE( "effective_food_volume_and_satiety", "[character][food][satiety]" )
REQUIRE( apple.weight() == 200_gram );
REQUIRE( apple.volume() == 250_ml );
REQUIRE( apple_nutr.kcal() == 95 );
REQUIRE( apple.get_comestible()->quench == 3 );
// If kcal per gram < 1.0, return 1.0
CHECK( u.compute_effective_food_volume_ratio( apple ) == Approx( 1.0f ).margin( 0.01f ) );
CHECK( u.compute_calories_per_effective_volume( apple ) == 500 );
CHECK( u.compute_calories_per_effective_volume( apple ) == 502 );
CHECK( satiety_bar( 500 ) == "<color_c_yellow>||\\</color>.." );

// Egg: 80 kcal / 40 g (1 serving)
Expand All @@ -295,10 +300,11 @@ TEST_CASE( "effective_food_volume_and_satiety", "[character][food][satiety]" )
REQUIRE( egg.weight() == 40_gram );
REQUIRE( egg.volume() == 50_ml );
REQUIRE( egg_nutr.kcal() == 80 );
REQUIRE( egg.get_comestible()->quench == 4 );
// If kcal per gram > 1.0 but less than 3.0, return ( kcal / gram )
CHECK( u.compute_effective_food_volume_ratio( egg ) == Approx( 2.0f ).margin( 0.01f ) );
CHECK( u.compute_calories_per_effective_volume( egg ) == 2000 );
CHECK( satiety_bar( 2000 ) == "<color_c_green>|||||</color>" );
CHECK( u.compute_calories_per_effective_volume( egg ) == 1777 );
CHECK( satiety_bar( 1777 ) == "<color_c_green>||||\\</color>" );

// Pine nuts: 202 kcal / 30 g (4 servings)
const item nuts( "test_pine_nuts" );
Expand All @@ -308,11 +314,17 @@ TEST_CASE( "effective_food_volume_and_satiety", "[character][food][satiety]" )
REQUIRE( nuts.weight() == 120_gram );
REQUIRE( nuts.volume() == 250_ml );
REQUIRE( nuts_nutr.kcal() == 202 );
REQUIRE( nuts.get_comestible()->quench == -2 );
// If kcal per gram > 3.0, return sqrt( 3 * kcal / gram )
expect_ratio = std::sqrt( 3.0f * 202 / 30 );
CHECK( u.compute_effective_food_volume_ratio( nuts ) == Approx( expect_ratio ).margin( 0.01f ) );
CHECK( u.compute_calories_per_effective_volume( nuts ) == 1498 );
CHECK( satiety_bar( 1498 ) == "<color_c_green>||||\\</color>" );
CHECK( u.compute_calories_per_effective_volume( nuts ) == 1507 );
CHECK( satiety_bar( 1507 ) == "<color_c_light_green>||||</color>." );

REQUIRE( u.mutate_towards( trait_GOURMAND ) );
CHECK( u.compute_effective_food_volume_ratio( egg ) == Approx( 2.0f ).margin( 0.01f ) );
CHECK( u.compute_calories_per_effective_volume( egg ) == 1568 );
CHECK( satiety_bar( 1568 ) == "<color_c_green>||||</color>." );
}

// satiety_bar returns a colorized string indicating a satiety level, similar to hit point bars
Expand All @@ -331,17 +343,22 @@ TEST_CASE( "food_satiety_bar", "[character][food][satiety]" )
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
CHECK( satiety_bar( 200 ) == "<color_c_light_red>|\\</color>..." );
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
CHECK( satiety_bar( 300 ) == "<color_c_yellow>||</color>..." );
CHECK( satiety_bar( 400 ) == "<color_c_yellow>||\\</color>.." );
CHECK( satiety_bar( 300 ) == "<color_c_yellow>|\\</color>..." );
CHECK( satiety_bar( 400 ) == "<color_c_yellow>||</color>..." );
CHECK( satiety_bar( 500 ) == "<color_c_yellow>||\\</color>.." );
CHECK( satiety_bar( 600 ) == "<color_c_light_green>|||</color>.." );
CHECK( satiety_bar( 700 ) == "<color_c_light_green>|||</color>.." );
CHECK( satiety_bar( 800 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 900 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 1000 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1100 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1200 ) == "<color_c_green>||||</color>." );
CHECK( satiety_bar( 1300 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 1400 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 1500 ) == "<color_c_green>|||||</color>" );
CHECK( satiety_bar( 600 ) == "<color_c_yellow>||\\</color>.." );
CHECK( satiety_bar( 700 ) == "<color_c_yellow>||\\</color>.." );
CHECK( satiety_bar( 800 ) == "<color_c_light_green>|||</color>.." );
CHECK( satiety_bar( 900 ) == "<color_c_light_green>|||</color>.." );
CHECK( satiety_bar( 1000 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 1100 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 1200 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 1300 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1400 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1500 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1600 ) == "<color_c_green>||||</color>." );
CHECK( satiety_bar( 1700 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 1800 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 1900 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 2000 ) == "<color_c_green>|||||</color>" );
}

0 comments on commit 3a0dfeb

Please sign in to comment.