From 1b6db56d1e3e5ae5e11a6b1f07369b7692bc7c94 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Sat, 18 Jan 2020 13:32:16 -0500 Subject: [PATCH] make helper function --- tests/hiking_test.cpp | 128 +++++++++++------------------------------- 1 file changed, 33 insertions(+), 95 deletions(-) diff --git a/tests/hiking_test.cpp b/tests/hiking_test.cpp index 814f1b6d8444b..686c874f0ee19 100644 --- a/tests/hiking_test.cpp +++ b/tests/hiking_test.cpp @@ -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 ¢er, avatar &dummy ) { @@ -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(); @@ -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 ); } }