Skip to content

Commit

Permalink
make helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Jan 18, 2020
1 parent 93e65e4 commit 1b6db56
Showing 1 changed file with 33 additions and 95 deletions.
128 changes: 33 additions & 95 deletions tests/hiking_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "avatar.h"
#include "avatar_action.h"
#include "calendar.h"
#include "character.h"
#include "game.h"
#include "map.h"
#include "map_helpers.h"
#include "player_helpers.h"
#include "point.h"
#include "units.h"

static void remain_centered( const tripoint &center, avatar &dummy )
{
Expand Down Expand Up @@ -53,6 +55,26 @@ static bool between( const int num, const int lower, const int high )
return num < high && num > lower;
}

static void test_carry( units::mass carry_weight, int min_cal, int max_cal,
character_movemode mode = character_movemode::CMM_WALK )
{
item bag( "bigback" );
REQUIRE( carry_weight >= bag.weight() );
carry_weight -= bag.weight();
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
if( mode == character_movemode::CMM_RUN ) {
dummy.toggle_run_mode();
}
dummy.i_add( bag );
dummy.wear( bag, false );
dummy.i_add( item( "thread", calendar::turn, units::to_gram( carry_weight ) ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, min_cal, max_cal ) );
}

TEST_CASE( "naked_walk", "[hike]" )
{
clear_player();
Expand All @@ -75,122 +97,38 @@ TEST_CASE( "naked_run", "[hike]" )
TEST_CASE( "walk_carry", "[hike]" )
{
SECTION( "10 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
item &backpack = dummy.i_add( item( "backpack" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 9367 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 230, 260 ) );
test_carry( 10000_gram, 230, 260 );
}
SECTION( "20 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
item &backpack = dummy.i_add( item( "backpack" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 19367 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 242, 272 ) );
test_carry( 20000_gram, 242, 272 );
}
SECTION( "30 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 26461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 270, 300 ) );
test_carry( 30000_gram, 270, 300 );
}
SECTION( "40 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 36461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 306, 336 ) );
test_carry( 40000_gram, 306, 336 );
}
SECTION( "60 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 56461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 412, 442 ) );
test_carry( 60000_gram, 412, 442 );
}
}

TEST_CASE( "run_carry", "[hike]" )
{
const character_movemode run = character_movemode::CMM_RUN;
SECTION( "10 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
dummy.toggle_run_mode();
item &backpack = dummy.i_add( item( "backpack" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 9367 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 1120, 1140 ) );
test_carry( 10000_gram, 1120, 1140, run );
}
SECTION( "20 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
dummy.toggle_run_mode();
item &backpack = dummy.i_add( item( "backpack" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 19367 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 1180, 1200 ) );
test_carry( 20000_gram, 1180, 1200, run );
}
SECTION( "30 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
dummy.toggle_run_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 26461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 1260, 1280 ) );
test_carry( 30000_gram, 1260, 1280, run );
}
SECTION( "40 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
dummy.toggle_run_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 36461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 1400, 1420 ) );
test_carry( 40000_gram, 1400, 1420, run );
}
SECTION( "60 kg" ) {
clear_player();
avatar &dummy = g->u;
dummy.reset_move_mode();
dummy.toggle_run_mode();
item &backpack = dummy.i_add( item( "bigback" ) );
dummy.wear( backpack, false );
dummy.i_add( item( "thread", calendar::turn, 56461 ) );
const int cal_spent = distance_test( dummy, 1_hours );
CAPTURE( cal_spent );
CHECK( between( cal_spent, 1880, 1900 ) );
test_carry( 60000_gram, 1880, 1900, run );
}
}

0 comments on commit 1b6db56

Please sign in to comment.