Skip to content

Commit

Permalink
Add effect duration/intensity/decay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed May 2, 2020
1 parent 25e1929 commit 0cced3b
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 32 deletions.
16 changes: 16 additions & 0 deletions data/mods/TEST_DATA/effects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"type": "effect_type",
"id": "debugged",
"name": [ "Debugged" ],
"desc": [ "You have been debugged!\nEverything is working perfectly now.." ],
"apply_message": "Diving into your source, you find a rubber duck, and talk it to death.",
"rating": "good",
"int_dur_factor": "1 m",
"max_duration": "1 h",
"max_intensity": 10,
"base_mods": { "healing_rate": [ 2 ], "healing_head": [ 200 ], "healing_torso": [ 150 ] },
"scaling_mods": { "per_mod": [ 5 ], "int_mod": [ 10 ] },
"show_in_info": true
}
]
195 changes: 163 additions & 32 deletions tests/effect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,6 @@

// Test `effect` class

// To cover:
//
// decay:
// - decay intensity and duration
// - add to removal list if duration <= 0
//
// Duration:
// get_start_time
// get_max_duration
// get_duration
// set_duration
// mod_duration
// mult_duration
//
// Intensity:
// get_intensity
// get_max_intensity
// set_intensity
// mod_intensity
// get_dur_add_perc
// get_int_dur_factor
// get_int_add_val
//
// Modifier type:
// get_mod
// get_avg_mod
// get_amount
// get_min_val
// get_max_val
// get_sizing
// get_percentage

// Create an `effect` object with given parameters, and check they were initialized correctly.
static void check_effect_init( const std::string eff_name, const time_duration dur,
const std::string bp_name, const bool permanent, const int intensity,
Expand All @@ -60,6 +28,150 @@ TEST_CASE( "effect initialization test", "[effect][init]" )
check_effect_init( "bite", 1_minutes, "torso", false, 2, calendar::turn );
}

// Duration:
// effect::get_start_time
// effect::get_max_duration
// effect::get_duration
// effect::set_duration
// effect::mod_duration
// effect::mult_duration
//
TEST_CASE( "effect duration", "[effect][duration]" )
{
const efftype_id eff_id( "debugged" );
effect effect_obj( &eff_id.obj(), 1_minutes, num_bp, false, 1, calendar::turn );

// max_duration comes from JSON effect data (data/mods/TEST_DATA/effects.json)
REQUIRE( effect_obj.get_duration() == 1_minutes );
REQUIRE( effect_obj.get_max_duration() == 1_hours );

SECTION( "duration can be set to a negative value" ) {
effect_obj.set_duration( -1_turns );
CHECK( to_turns<int>( effect_obj.get_duration() ) == -1 );
}

SECTION( "set_duration is capped at maximum duration" ) {
effect_obj.set_duration( 2_hours );
CHECK( effect_obj.get_duration() == 1_hours );
}

// set_duration
// - forces intensity if it is duration based (int_dur_factor)
// - (lowest intensity is 1 not 0)
}

// Intensity
//
// effect::get_intensity
// effect::get_max_intensity
// effect::set_intensity
// effect::mod_intensity
//
// TODO:
// get_dur_add_perc
// get_int_dur_factor
// get_int_add_val
TEST_CASE( "effect intensity", "[effect][intensity]" )
{
const efftype_id eff_id( "debugged" );
effect effect_obj( &eff_id.obj(), 3_turns, num_bp, false, 1, calendar::turn );

REQUIRE( effect_obj.get_intensity() == 1 );
REQUIRE( effect_obj.get_max_intensity() == 10 );

SECTION( "intensity cannot be set less than 1" ) {
effect_obj.set_intensity( 0 );
CHECK( effect_obj.get_intensity() == 1 );
effect_obj.set_intensity( -1 );
CHECK( effect_obj.get_intensity() == 1 );
}

SECTION( "intensity cannot be set greater than maximum" ) {
// These don't go to 11
effect_obj.set_intensity( 11 );
CHECK( effect_obj.get_intensity() == 10 );
// or 9+2
effect_obj.set_intensity( 9 );
effect_obj.mod_intensity( 2 );
CHECK( effect_obj.get_intensity() == 10 );
}

// From JSON:
// max_intensity: Used for many later fields, defaults to 1
// max_effective_intensity: How many intensity levels will apply effects. Other intensity levels
// will only increase duration.
//
// If "max_intensity" > 1 and the number of entries in "name" >= "max_intensity" then it will
// attempt to use the proper intensity name.
}

// effect::decay
//
// - decay intensity and duration
// - add to removal list if duration <= 0
//
TEST_CASE( "effect decay", "[effect][decay]" )
{
const efftype_id eff_id( "debugged" );

std::vector<efftype_id> rem_ids;
std::vector<body_part> rem_bps;

SECTION( "decay reduces effect duration by 1 turn" ) {
effect debugged( &eff_id.obj(), 2_turns, num_bp, false, 1, calendar::turn );
// Ensure it will last 2 turns, and is not permanent/paused
REQUIRE( to_turns<int>( debugged.get_duration() ) == 2 );
REQUIRE_FALSE( debugged.is_permanent() );

// First decay - 1 turn left
debugged.decay( rem_ids, rem_bps, calendar::turn, false );
CHECK( to_turns<int>( debugged.get_duration() ) == 1 );
// Effect not removed
CHECK( rem_ids.empty() );
CHECK( rem_bps.empty() );

// Second decay - 0 turns left
debugged.decay( rem_ids, rem_bps, calendar::turn, false );
CHECK( to_turns<int>( debugged.get_duration() ) == 0 );
// Effect still not removed
CHECK( rem_ids.empty() );
CHECK( rem_bps.empty() );

// Third decay - 0 turns left
debugged.decay( rem_ids, rem_bps, calendar::turn, false );
CHECK( to_turns<int>( debugged.get_duration() ) == 0 );
// Effect is removed
CHECK( rem_ids.size() == 1 );
CHECK( rem_bps.size() == 1 );
// Effect ID and body part are pushed to the arrays
CHECK( rem_ids.front() == debugged.get_id() );
CHECK( rem_bps.front() == num_bp );
}

SECTION( "decay does not reduce paused/permanent effect duration" ) {
effect debugged( &eff_id.obj(), 2_turns, num_bp, true, 1, calendar::turn );
// Ensure it will last 2 turns, and is permanent/paused
REQUIRE( to_turns<int>( debugged.get_duration() ) == 2 );
REQUIRE( debugged.is_permanent() );

// Decay twice - should have no effect on duration
debugged.decay( rem_ids, rem_bps, calendar::turn, false );
CHECK( to_turns<int>( debugged.get_duration() ) == 2 );
debugged.decay( rem_ids, rem_bps, calendar::turn, false );
CHECK( to_turns<int>( debugged.get_duration() ) == 2 );
}

// TODO:
// When intensity > 1
// - and duration < max_duration
// - and int_decay_tick is set (from effect JSON)
// - and time % decay_tick == 0
// Then:
// - add int_decay_step to intensity (default -1)
}

// effect::disp_short_desc
//
TEST_CASE( "display short description", "[effect][desc]" )
{
const efftype_id eff_id( "grabbed" );
Expand All @@ -75,6 +187,10 @@ TEST_CASE( "display short description", "[effect][desc]" )
"You are being held in place, and dodging and blocking are very difficult." );
}

// effect::is_permanent
// effect::pause_effect
// effect::unpause_effect
//
TEST_CASE( "effect permanence", "[effect][permanent]" )
{
const efftype_id eff_id( "grabbed" );
Expand All @@ -97,6 +213,9 @@ TEST_CASE( "effect permanence", "[effect][permanent]" )
CHECK_FALSE( grabbed.is_permanent() );
}

// effect::set_bp
// effect::get_bp
//
TEST_CASE( "effect body part", "[effect][bodypart]" )
{
const efftype_id eff_id( "grabbed" );
Expand All @@ -116,3 +235,15 @@ TEST_CASE( "effect body part", "[effect][bodypart]" )
CHECK_FALSE( grabbed.get_bp() == arm_l );
}

// TODO: Modifier types
// get_mod
// get_avg_mod
// get_amount
// get_min_val
// get_max_val
// get_sizing
// get_percentage
TEST_CASE( "effect modifiers", "[effect][modifier]" )
{
}

0 comments on commit 0cced3b

Please sign in to comment.