diff --git a/tests/iteminfo_test.cpp b/tests/iteminfo_test.cpp index 7c7fdd7c80cc1..19287b5135cdc 100644 --- a/tests/iteminfo_test.cpp +++ b/tests/iteminfo_test.cpp @@ -3,10 +3,12 @@ #include #include "avatar.h" +#include "calendar.h" #include "catch/catch.hpp" #include "game.h" #include "item.h" #include "iteminfo_query.h" +#include "itype.h" #include "recipe_dictionary.h" static void iteminfo_test( const item &i, const iteminfo_query &q, const std::string &reference ) @@ -17,88 +19,298 @@ static void iteminfo_test( const item &i, const iteminfo_query &q, const std::st CHECK( info == reference ); } -TEST_CASE( "armor_info", "[item][iteminfo]" ) +TEST_CASE( "item description and physical attributes", "[item][iteminfo]" ) { - // Just a generic typical piece of clothing - iteminfo_query q( { iteminfo_parts::ARMOR_BODYPARTS, iteminfo_parts::ARMOR_LAYER, - iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH, - iteminfo_parts::ARMOR_ENCUMBRANCE, iteminfo_parts::ARMOR_PROTECTION - } ); + iteminfo_query q( { iteminfo_parts::DESCRIPTION, iteminfo_parts::BASE_CATEGORY, + iteminfo_parts::BASE_PRICE, iteminfo_parts::BASE_VOLUME, + iteminfo_parts::BASE_WEIGHT, iteminfo_parts::BASE_MATERIAL } ); iteminfo_test( - item( "longshirt" ), q, + item( "jug_plastic" ), q, + "A standard plastic jug used for milk and household cleaning chemicals.\n" "--\n" - // NOLINTNEXTLINE(cata-text-style) - "Covers: The torso. The arms. \n" - // NOLINTNEXTLINE(cata-text-style) - "Layer: Normal. \n" - "Coverage: 90% Warmth: 5\n" + "Category: CONTAINERS Price: $0.00\n" + "Volume: 3.750 L" + " Weight: 0.42 lbs\n" "--\n" - "Encumbrance: 3 (poor fit)\n" - "Protection: Bash: 1 Cut: 1\n" - " Acid: 0 Fire: 0 Environmental: 0\n" ); + "Material: Plastic\n" ); + } -TEST_CASE( "if_covers_nothing_omit_irreelevant_info", "[item][iteminfo]" ) +TEST_CASE( "weapon attack ratings and moves", "[item][iteminfo]" ) { - iteminfo_query q( { iteminfo_parts::ARMOR_BODYPARTS, iteminfo_parts::ARMOR_LAYER, - iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH, - iteminfo_parts::ARMOR_ENCUMBRANCE, iteminfo_parts::ARMOR_PROTECTION - } ); + iteminfo_query q( { iteminfo_parts::BASE_DAMAGE, iteminfo_parts::BASE_TOHIT, + iteminfo_parts::BASE_MOVES } ); + iteminfo_test( - item( "ear_plugs" ), q, - "--\n" - "Covers: Nothing.\n" ); + item( "halligan" ), q, + "Bash: 20" + " Cut: 5" + " To-hit bonus: +2\n" + "Moves per attack: 145\n" ); + } -TEST_CASE( "gun_lists_default_ammo", "[item][iteminfo]" ) +TEST_CASE( "techniques when wielded", "[item][iteminfo]" ) { - iteminfo_query q( { iteminfo_parts::GUN_DEFAULT_AMMO } ); + iteminfo_query q( { iteminfo_parts::DESCRIPTION_TECHNIQUES } ); + iteminfo_test( - item( "compbow" ), q, + item( "halligan" ), q, "--\n" - "Gun is not loaded, so stats below assume the default ammo: wooden broadhead arrow\n" ); + "Techniques when wielded:" + " Brutal Strike: Stun 1 turn, knockback 1 tile, crit only," + " Sweep Attack: Down 2 turns, and" + " Block: Medium blocking ability\n" ); + } -TEST_CASE( "gun_damage_multiplier_not_integer", "[item][iteminfo]" ) +TEST_CASE( "armor coverage and protection values", "[item][iteminfo]" ) { - iteminfo_query q( { iteminfo_parts::GUN_DAMAGE, iteminfo_parts::GUN_DAMAGE_AMMOPROP, - iteminfo_parts::GUN_DAMAGE_TOTAL + iteminfo_query q( { iteminfo_parts::ARMOR_BODYPARTS, iteminfo_parts::ARMOR_LAYER, + iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH, + iteminfo_parts::ARMOR_ENCUMBRANCE, iteminfo_parts::ARMOR_PROTECTION } ); - iteminfo_test( - item( "compbow" ), q, - "--\n" - "Damage: 18*1.25 = 22\n" ); + + SECTION( "shows coverage, encumbrance, and protection for armor with coverage" ) { + iteminfo_test( + item( "longshirt" ), q, + "--\n" + // NOLINTNEXTLINE(cata-text-style) + "Covers: The torso. The arms. \n" + // NOLINTNEXTLINE(cata-text-style) + "Layer: Normal. \n" + "Coverage: 90% Warmth: 5\n" + "--\n" + "Encumbrance: 3 (poor fit)\n" + "Protection: Bash: 1 Cut: 1\n" + " Acid: 0 Fire: 0 Environmental: 0\n" ); + } + + SECTION( "omits irrelevant info if it covers nothing" ) { + iteminfo_test( + item( "ear_plugs" ), q, + "--\n" + "Covers: Nothing.\n" ); + } } -TEST_CASE( "nutrients_in_regular_item", "[item][iteminfo]" ) +TEST_CASE( "ranged weapon attributes", "[item][iteminfo]" ) +{ + SECTION( "ammo capacity" ) { + iteminfo_query q( { iteminfo_parts::GUN_CAPACITY } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Capacity: 1 round of arrows\n" ); + } + + SECTION( "default ammo when unloaded" ) { + iteminfo_query q( { iteminfo_parts::GUN_DEFAULT_AMMO } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Gun is not loaded, so stats below assume the default ammo:" + " wooden broadhead arrow\n" ); + } + + SECTION( "damage including floating-point multiplier" ) { + iteminfo_query q( { iteminfo_parts::GUN_DAMAGE, iteminfo_parts::GUN_DAMAGE_AMMOPROP, + iteminfo_parts::GUN_DAMAGE_TOTAL + } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Damage: 18*1.25 = 22\n" ); + } + + SECTION( "time to reload" ) { + iteminfo_query q( { iteminfo_parts::GUN_RELOAD_TIME } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Reload time: 110 moves \n" ); // NOLINT(cata-text-style) + } + + SECTION( "firing modes" ) { + iteminfo_query q( { iteminfo_parts::GUN_FIRE_MODES } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Fire modes: manual (1)\n" ); + } + + SECTION( "weapon mods" ) { + iteminfo_query q( { iteminfo_parts::DESCRIPTION_GUN_MODS } ); + iteminfo_test( + item( "compbow" ), q, + "--\n" + "Mods: 0/2 accessories;" + " 0/1 dampening; 0/1 sights;" + " 0/1 stabilizer; 0/1 underbarrel.\n" ); + } + +} + +TEST_CASE( "nutrients in food", "[item][iteminfo]" ) { iteminfo_query q( { iteminfo_parts::FOOD_NUTRITION, iteminfo_parts::FOOD_VITAMINS, iteminfo_parts::FOOD_QUENCH } ); - item i( "icecream" ); + SECTION( "fixed nutrient values in regular item" ) { + item i( "icecream" ); + iteminfo_test( + i, q, + "--\n" + "Calories (kcal): 325 " + "Quench: 0\n" + "Vitamins (RDA): Calcium (9%), Vitamin A (9%), and Vitamin B12 (11%)\n" ); + } + + SECTION( "nutrient ranges for recipe exemplars", "[item][iteminfo]" ) { + item i( "icecream" ); + i.set_var( "recipe_exemplar", "icecream" ); + iteminfo_test( + i, q, + "--\n" + "Nutrition will vary with chosen ingredients.\n" + "Calories (kcal): 317-" + "469 Quench: 0\n" + "Vitamins (RDA): Calcium (7-28%), Iron (0-83%), " + "Vitamin A (3-11%), Vitamin B12 (2-6%), and Vitamin C (1-85%)\n" ); + } +} + +TEST_CASE( "food freshness and lifetime", "[item][iteminfo]" ) +{ + iteminfo_query q( { iteminfo_parts::FOOD_ROT } ); + + // Ensure test character has no skill estimating spoilage + g->u.empty_skills(); + REQUIRE_FALSE( g->u.can_estimate_rot() ); + + SECTION( "food is fresh" ) { + iteminfo_test( + item( "pine_nuts" ), q, + "--\n" + "* This food is perishable, and at room temperature has" + " an estimated nominal shelf life of 6 weeks.\n" + "* This food looks as fresh as it can be.\n" ); + } + + SECTION( "food is old" ) { + item nuts( "pine_nuts" ); + nuts.mod_rot( nuts.type->comestible->spoils ); + iteminfo_test( + nuts, q, + "--\n" + "* This food is perishable, and at room temperature has" + " an estimated nominal shelf life of 6 weeks.\n" + "* This food looks old. It's on the brink of becoming inedible.\n" ); + } + +} + + +TEST_CASE( "item conductivity", "[item][iteminfo]" ) +{ + iteminfo_query q( { iteminfo_parts::DESCRIPTION_CONDUCTIVITY } ); + + SECTION( "non-conductive items" ) { + iteminfo_test( + item( "2x4" ), q, + "--\n" + "* This item does not conduct electricity.\n" ); + iteminfo_test( + item( "fire_ax" ), q, + "--\n" + "* This item does not conduct electricity.\n" ); + } + + SECTION( "conductive items" ) { + iteminfo_test( + item( "pipe" ), q, + "--\n" + "* This item conducts electricity.\n" ); + iteminfo_test( + item( "halligan" ), q, + "--\n" + "* This item conducts electricity.\n" ); + } +} + +TEST_CASE( "list of item qualities", "[item][iteminfo]" ) +{ + iteminfo_query q( { iteminfo_parts::QUALITIES } ); + + SECTION( "screwdriver" ) { + iteminfo_test( + item( "screwdriver" ), q, + "--\n" + "Has level 1 screw driving quality.\n" ); + } + + SECTION( "screwdriver set" ) { + iteminfo_test( + item( "screwdriver_set" ), q, + "--\n" + "Has level 1 screw driving quality.\n" + "Has level 1 fine screw driving quality.\n" ); + } + + SECTION( "Halligan bar" ) { + iteminfo_test( + item( "halligan" ), q, + "--\n" + "Has level 1 digging quality.\n" + "Has level 2 hammering quality.\n" + "Has level 4 prying quality.\n" ); + } +} + +TEST_CASE( "repairable and with what tools", "[item][iteminfo]" ) +{ + iteminfo_query q( { iteminfo_parts::DESCRIPTION_REPAIREDWITH } ); + iteminfo_test( - i, q, + item( "halligan" ), q, "--\n" - "Calories (kcal): 325 " - "Quench: 0\n" - "Vitamins (RDA): Calcium (9%), Vitamin A (9%), and Vitamin B12 (11%)\n" ); + "Repaired with: extended toolset, arc welder, or makeshift arc welder\n" ); + + iteminfo_test( + item( "hazmat_suit" ), q, + "--\n" + "Repaired with: soldering iron or extended toolset\n" ); + + iteminfo_test( + item( "rock" ), q, + "--\n" + "* This item is not repairable.\n" ); } -TEST_CASE( "nutrient_ranges_for_recipe_exemplars", "[item][iteminfo]" ) +TEST_CASE( "item description flags", "[item][iteminfo]" ) { - iteminfo_query q( { iteminfo_parts::FOOD_NUTRITION, iteminfo_parts::FOOD_VITAMINS, - iteminfo_parts::FOOD_QUENCH - } ); - item i( "icecream" ); - i.set_var( "recipe_exemplar", "icecream" ); + iteminfo_query q( { iteminfo_parts::DESCRIPTION_FLAGS } ); + iteminfo_test( - i, q, + item( "halligan" ), q, "--\n" - "Nutrition will vary with chosen ingredients.\n" - "Calories (kcal): 317-" - "469 Quench: 0\n" - "Vitamins (RDA): Calcium (7-28%), Iron (0-83%), " - "Vitamin A (3-11%), Vitamin B12 (2-6%), and Vitamin C (1-85%)\n" ); + "* This item can be clipped on to a belt loop of the appropriate size.\n" + "* As a weapon, this item is well-made and will" + " withstand the punishment of combat.\n" ); + + iteminfo_test( + item( "hazmat_suit" ), q, + "--\n" + "* This gear completely protects you from" + " electric discharges.\n" + "* This gear completely protects you from" + " any gas.\n" + "* This gear is generally worn over clothing.\n" + "* This clothing completely protects you from" + " radiation.\n" + "* This piece of clothing is designed to keep you dry in the rain.\n" + "* This clothing won't let water through." + " Unless you jump in the river or something like that.\n" ); } TEST_CASE( "show available recipes with item as an ingredient", "[item][iteminfo][recipes]" ) @@ -154,4 +366,3 @@ TEST_CASE( "show available recipes with item as an ingredient", "[item][iteminfo } } } -