Skip to content

Commit

Permalink
Add test apple and quiver, food allergy info test
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed May 28, 2020
1 parent 14ae36c commit 9c2dfd7
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 17 deletions.
44 changes: 44 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,29 @@
"quench": -50,
"fun": -20
},
{
"id": "test_apple",
"type": "COMESTIBLE",
"comestible_type": "FOOD",
"category": "food",
"name": { "str": "test apple" },
"description": "Test apple. May contain worms, but tastes delicious!",
"volume": "250 ml",
"weight": "200 g",
"color": "red",
"spoils_in": "5 days",
"symbol": "%",
"quench": 3,
"healthy": -1,
"calories": 95,
"price": 900,
"price_postapoc": 100,
"material": "fruit",
"fun": 10,
"flags": [ "FREEZERBURN", "SMOKABLE" ],
"smoking_result": "dry_fruit",
"vitamins": [ [ "vitA", 2 ], [ "vitC", 14 ], [ "iron", 1 ] ]
},
{
"id": "test_jug_plastic",
"type": "GENERIC",
Expand Down Expand Up @@ -596,6 +619,27 @@
"material_thickness": 2,
"flags": [ "FANCY", "OVERSIZE", "BELTED", "RESTRICT_HANDS", "WATER_FRIENDLY" ]
},
{
"id": "test_quiver",
"type": "ARMOR",
"name": { "str": "test quiver" },
"description": "Quiver of Testing, with room for 20 arrows or bolts.",
"weight": "260 g",
"volume": "500 ml",
"price": 6500,
"price_postapoc": 1000,
"bashing": 2,
"material": [ "leather" ],
"symbol": "[",
"looks_like": "bscabbard",
"color": "brown",
"covers": [ "LEG_EITHER" ],
"coverage": 10,
"encumbrance": 3,
"material_thickness": 1,
"pocket_data": [ { "ammo_restriction": { "arrow": 20, "bolt": 20 }, "moves": 20 } ],
"flags": [ "WAIST", "OVERSIZE", "WATER_FRIENDLY" ]
},
{
"type": "GENERIC",
"id": "test_clumsy_sword",
Expand Down
74 changes: 57 additions & 17 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ TEST_CASE( "item owner", "[iteminfo][owner]" )
// item::basic_info
TEST_CASE( "item requirements", "[iteminfo][requirements]" )
{
clear_avatar();

std::vector<iteminfo_parts> reqs = { iteminfo_parts::BASE_REQUIREMENTS };

// TODO:
Expand Down Expand Up @@ -203,6 +205,7 @@ TEST_CASE( "item contents", "[iteminfo][contents]" )
// item::med_info
TEST_CASE( "med_info", "[iteminfo][med]" )
{
// Parts to test
std::vector<iteminfo_parts> quench = { iteminfo_parts::MED_QUENCH };
std::vector<iteminfo_parts> joy = { iteminfo_parts::MED_JOY };
std::vector<iteminfo_parts> stimulation = { iteminfo_parts::MED_STIMULATION };
Expand All @@ -217,29 +220,33 @@ TEST_CASE( "med_info", "[iteminfo][med]" )

CHECK( item_info_str( gum, quench ) ==
"--\nQuench: <color_c_yellow>50</color>\n" );

CHECK( item_info_str( gum, joy ) ==
"--\nEnjoyability: <color_c_yellow>5</color>\n" );

CHECK( item_info_str( gum, stimulation ) ==
"--\nStimulation: <color_c_light_blue>Upper</color>\n" );

CHECK( item_info_str( gum, portions ) ==
"--\nPortions: <color_c_yellow>10</color>\n" );

CHECK( item_info_str( gum, consume_time ) ==
"--\nConsume time: 5 seconds\n" );

CHECK( item_info_str( gum, addicting ) ==
"--\n* Consuming this item is <color_c_red>addicting</color>.\n" );
}

// Items with comestible_type "DRINK"
SECTION( "item that is not medication does not show med_info" ) {
item wine( "test_wine" );
REQUIRE_FALSE( wine.is_medication() );

CHECK( item_info_str( wine, quench ).empty() );
CHECK( item_info_str( wine, joy ).empty() );
CHECK( item_info_str( wine, stimulation ).empty() );
CHECK( item_info_str( wine, portions ).empty() );
CHECK( item_info_str( wine, consume_time ).empty() );
CHECK( item_info_str( wine, addicting ).empty() );
item apple( "test_apple" );
REQUIRE_FALSE( apple.is_medication() );

CHECK( item_info_str( apple, quench ).empty() );
CHECK( item_info_str( apple, joy ).empty() );
CHECK( item_info_str( apple, stimulation ).empty() );
CHECK( item_info_str( apple, portions ).empty() );
CHECK( item_info_str( apple, consume_time ).empty() );
CHECK( item_info_str( apple, addicting ).empty() );
}
}

Expand Down Expand Up @@ -300,8 +307,9 @@ TEST_CASE( "item debug info", "[iteminfo][debug]" )
TEST_CASE( "item price and barter value", "[iteminfo][price]" )
{
clear_avatar();

// Price and barter value are displayed together on a single line
std::vector<iteminfo_parts> price_barter = { iteminfo_parts::BASE_PRICE, iteminfo_parts::BASE_BARTER };
CHECK_FALSE( debug_mode );

SECTION( "item with different price and barter value" ) {
item pipe( "test_pipe" );
Expand Down Expand Up @@ -339,6 +347,7 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
{
clear_avatar();

// Rigidity and encumbrance are related; non-rigid items have flexible encumbrance.
std::vector<iteminfo_parts> rigidity = { iteminfo_parts::BASE_RIGIDITY };
std::vector<iteminfo_parts> encumbrance = { iteminfo_parts::ARMOR_ENCUMBRANCE };

Expand All @@ -353,7 +362,7 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) {
item waterskin( "test_waterskin" );
item backpack( "test_backpack" );
item quiver( "quiver" ); // FIXME: Add test_quiver
item quiver( "test_quiver" );

SECTION( "rigidity indicator" ) {
REQUIRE_FALSE( waterskin.contents.all_pockets_rigid() );
Expand Down Expand Up @@ -862,7 +871,6 @@ TEST_CASE( "gun or other ranged weapon attributes", "[iteminfo][weapon][gun]" )
}
// TODO: Test glock damage with and without ammo (test_glock has -1 damage when unloaded)


SECTION( "maximum range" ) {
std::vector<iteminfo_parts> max_range = { iteminfo_parts::GUN_MAX_RANGE };

Expand Down Expand Up @@ -1189,6 +1197,7 @@ TEST_CASE( "basic food info", "[iteminfo][food]" )
{
clear_avatar();

//
std::vector<iteminfo_parts> joy = { iteminfo_parts::FOOD_JOY };
std::vector<iteminfo_parts> portions = { iteminfo_parts::FOOD_PORTIONS };
std::vector<iteminfo_parts> consume_time = { iteminfo_parts::FOOD_CONSUME_TIME };
Expand All @@ -1197,10 +1206,6 @@ TEST_CASE( "basic food info", "[iteminfo][food]" )
//std::vector<iteminfo_parts> smell = { iteminfo_parts::FOOD_SMELL };
//std::vector<iteminfo_parts> vit_effects = { iteminfo_parts::FOOD_VIT_EFFECTS };
//std::vector<iteminfo_parts> cannibalism = { iteminfo_parts::FOOD_CANNIBALISM };
//std::vector<iteminfo_parts> poison = { iteminfo_parts::FOOD_POISON };
//std::vector<iteminfo_parts> allergen = { iteminfo_parts::FOOD_ALLERGEN };
//std::vector<iteminfo_parts> hallu = { iteminfo_parts::FOOD_HALLUCINOGENIC };
// "This food will cause an allergic reaction" - UN-GATED

item nuts( "test_pine_nuts" );
CHECK( item_info_str( nuts, joy ) ==
Expand All @@ -1210,6 +1215,14 @@ TEST_CASE( "basic food info", "[iteminfo][food]" )
CHECK( item_info_str( nuts, consume_time ) ==
"--\nConsume time: 12 seconds\n" );

item apple( "test_apple" );
CHECK( item_info_str( apple, joy ) ==
"--\nEnjoyability: <color_c_yellow>10</color>\n" );
CHECK( item_info_str( apple, portions ) ==
"--\nPortions: <color_c_yellow>1</color>\n" );
CHECK( item_info_str( apple, consume_time ) ==
"--\nConsume time: 50 seconds\n" );

item wine( "test_wine" );
CHECK( item_info_str( wine, joy ) ==
"--\nEnjoyability: <color_c_yellow>-5</color>\n" );
Expand All @@ -1219,6 +1232,33 @@ TEST_CASE( "basic food info", "[iteminfo][food]" )
"--\nConsume time: 2 seconds\n" );
}

// item::food_info
TEST_CASE( "food character is allergic to", "[iteminfo][food][allergy]" )
{
clear_avatar();

std::vector<iteminfo_parts> allergen = { iteminfo_parts::FOOD_ALLERGEN };

GIVEN( "character allergic to fruit" ) {
g->u.toggle_trait( trait_id( "ANTIFRUIT" ) );
REQUIRE( g->u.has_trait( trait_id( "ANTIFRUIT" ) ) );

THEN( "fruit indicates an allergic reaction" ) {
item apple( "test_apple" );
REQUIRE( apple.has_flag( "ALLERGEN_FRUIT" ) );
CHECK( item_info_str( apple, allergen ) ==
"--\n"
"* This food will cause an <color_c_red>allergic reaction</color>.\n" );
}

THEN( "nuts do not indicate an allergic reaction" ) {
item nuts( "test_pine_nuts" );
REQUIRE_FALSE( nuts.has_flag( "ALLERGEN_FRUIT" ) );
CHECK( item_info_str( nuts, allergen ).empty() );
}
}
}

// item::food_info
TEST_CASE( "food with hidden poison or hallucinogen", "[iteminfo][food][poison][hallu]" )
{
Expand Down

0 comments on commit 9c2dfd7

Please sign in to comment.