-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for limb scores and character modifiers
- Loading branch information
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[ | ||
{ | ||
"type": "limb_score", | ||
"id": "test", | ||
"name": "Testing", | ||
"affected_by_wounds": true, | ||
"affected_by_encumb": true | ||
}, | ||
{ | ||
"id": "test_tail", | ||
"type": "body_part", | ||
"name": "test tail", | ||
"name_multiple": "test tails", | ||
"heading": "TST Tail", | ||
"heading_multiple": "Tails", | ||
"encumbrance_text": "Your testing tail feels heavy", | ||
"hit_size": 1, | ||
"hit_size_relative": [ 0, 0, 0 ], | ||
"drench_capacity": 4, | ||
"main_part": "test_tail", | ||
"hit_difficulty": 0.8, | ||
"limb_type": "tail", | ||
"opposite_part": "test_tail", | ||
"connected_to": "torso", | ||
"side": "both", | ||
"accusative": { "ctxt": "bodypart_accusative", "str": "test tail" }, | ||
"hp_bar_ui_text": "TST TAIL", | ||
"base_hp": 20, | ||
"limb_scores": [ [ "test", 0.8 ] ] | ||
}, | ||
{ | ||
"type": "enchantment", | ||
"id": "ENCH_TEST_TAIL", | ||
"condition": "ALWAYS", | ||
"modified_bodyparts": [ { "gain": "test_tail" } ] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"type": "character_mod", | ||
"id": "test_char_cost_mod", | ||
"description": "Test character cost modifier", | ||
"mod_type": "x", | ||
"value": { "limb_score": "test", "limb_type": "tail", "max": 1000.0, "nominator": 30.0, "subtract": 30.0 } | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "bodypart.h" | ||
#include "cata_catch.h" | ||
#include "character_modifier.h" | ||
#include "magic_enchantment.h" | ||
#include "player_helpers.h" | ||
|
||
static const bodypart_str_id bodypart_test_tail( "test_tail" ); | ||
static const character_modifier_id character_modifier_test_char_cost_mod( "test_char_cost_mod" ); | ||
static const enchantment_id enchantment_ENCH_TEST_TAIL( "ENCH_TEST_TAIL" ); | ||
static const itype_id itype_test_tail_encumber( "test_tail_encumber" ); | ||
static const limb_score_id limb_score_test( "test" ); | ||
|
||
static void create_char( Character &dude ) | ||
{ | ||
clear_character( dude, true ); | ||
|
||
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_TAIL ); | ||
dude.recalculate_bodyparts(); | ||
REQUIRE( dude.has_part( bodypart_test_tail ) ); | ||
} | ||
|
||
TEST_CASE( "Basic limb score test", "[character][encumbrance]" ) | ||
{ | ||
standard_npc dude( "Test NPC" ); | ||
create_char( dude ); | ||
const bodypart *test_bp = dude.get_part( bodypart_test_tail ); | ||
REQUIRE( test_bp != nullptr ); | ||
|
||
GIVEN( "limb is not encumbered" ) { | ||
WHEN( "limb is not wounded" ) { | ||
THEN( "modified limb score equals unmodified limb score" ) { | ||
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) ); | ||
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) ); | ||
} | ||
} | ||
WHEN( "limb is wounded" ) { | ||
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true ); | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) ); | ||
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.53333 ).epsilon( 0.001 ) ); | ||
} | ||
} | ||
} | ||
|
||
GIVEN( "limb is encumbered" ) { | ||
item it( itype_test_tail_encumber ); | ||
dude.wear_item( it, false ); | ||
WHEN( "limb is not wounded" ) { | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) ); | ||
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.4701 ).epsilon( 0.001 ) ); | ||
} | ||
} | ||
WHEN( "limb is wounded" ) { | ||
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true ); | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( test_bp->get_id()->get_limb_score( limb_score_test ) == Approx( 0.8 ).epsilon( 0.001 ) ); | ||
CHECK( dude.get_limb_score( limb_score_test ) == Approx( 0.3134 ).epsilon( 0.001 ) ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
TEST_CASE( "Basic character modifier test", "[character][encumbrance]" ) | ||
{ | ||
standard_npc dude( "Test NPC" ); | ||
create_char( dude ); | ||
const bodypart *test_bp = dude.get_part( bodypart_test_tail ); | ||
REQUIRE( test_bp != nullptr ); | ||
REQUIRE( character_modifier_test_char_cost_mod->use_limb_score() == limb_score_test ); | ||
|
||
GIVEN( "limb is not encumbered" ) { | ||
WHEN( "limb is not wounded" ) { | ||
THEN( "modified limb score equals unmodified limb score" ) { | ||
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 7.5 ).epsilon( | ||
0.001 ) ); | ||
} | ||
} | ||
WHEN( "limb is wounded" ) { | ||
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true ); | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 26.25 ).epsilon( | ||
0.001 ) ); | ||
} | ||
} | ||
} | ||
|
||
GIVEN( "limb is encumbered" ) { | ||
item it( itype_test_tail_encumber ); | ||
dude.wear_item( it, false ); | ||
WHEN( "limb is not wounded" ) { | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 33.81579 ).epsilon( | ||
0.001 ) ); | ||
} | ||
} | ||
WHEN( "limb is wounded" ) { | ||
dude.apply_damage( nullptr, test_bp->get_id(), test_bp->get_hp_max() / 2, true ); | ||
THEN( "modified limb score is less than unmodified limb score" ) { | ||
CHECK( dude.get_modifier( character_modifier_test_char_cost_mod ) == Approx( 65.72368 ).epsilon( | ||
0.001 ) ); | ||
} | ||
} | ||
} | ||
} |