Skip to content

Commit

Permalink
WIP Improve item recipe tests (still failing)
Browse files Browse the repository at this point in the history
Test coverage for modified item info behavior
  • Loading branch information
wapcaplet committed Feb 9, 2020
1 parent 3ffc4f0 commit 3561ef3
Showing 1 changed file with 65 additions and 22 deletions.
87 changes: 65 additions & 22 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "game.h"
#include "item.h"
#include "iteminfo_query.h"
#include "recipe_dictionary.h"

static void iteminfo_test( const item &i, const iteminfo_query &q, const std::string &reference )
{
Expand Down Expand Up @@ -100,42 +101,84 @@ TEST_CASE( "nutrient_ranges_for_recipe_exemplars", "[item][iteminfo]" )
"Vitamin A (3-11%), Vitamin B12 (2-6%), and Vitamin C (1-85%)\n" );
}

TEST_CASE( "show_available_recipes_using_item", "[item][iteminfo]" )
TEST_CASE( "show available recipes with item as an ingredient", "[item][iteminfo][recipes]" )
{
iteminfo_query q( { iteminfo_parts::DESCRIPTION_APPLICABLE_RECIPES } );
const recipe *crowbar = &recipe_id( "makeshift_crowbar" ).obj();
const recipe *purtab = &recipe_id( "pur_tablets" ).obj();
g->u.empty_skills();

GIVEN( "a character with no cooking skill" ) {
avatar character;
const recipe *pur = &recipe_id( "pur_tablets" ).obj();
GIVEN( "character has a pipe and no skill" ) {
item &pipe = g->u.i_add( item( "pipe" ) );

REQUIRE( character.get_skill_level( pur->skill_used ) == 0 );
REQUIRE_FALSE( character.knows_recipe( pur ) );
REQUIRE( g->u.get_skill_level( crowbar->skill_used ) == 0 );

WHEN( "they have potassium iodide tablets in their inventory" ) {
item &iodine = character.i_add( item( "iodine" ) );
THEN( "they can craft a makeshift crowbar from it" ) {
iteminfo_test(
pipe, q,
"--\nYou could use it to craft: <color_c_dark_gray>makeshift crowbar</color>\n" );
}
}

GIVEN( "character has potassium iodide tablets" ) {
item &iodine = g->u.i_add( item( "iodine" ) );

WHEN( "they don't have skills or recipes" ) {
g->u.set_skill_level( purtab->skill_used, 0 );

REQUIRE( g->u.get_skill_level( purtab->skill_used ) == 0 );
REQUIRE_FALSE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) );

THEN( "nothing is craftable from it" ) {
std::vector<iteminfo> info_v;
std::string info = iodine.info( info_v, &q, 1 );
CHECK( info == "--\nYou know of nothing you could craft with it.\n" );
iteminfo_test(
iodine, q,
"--\nYou know of nothing you could craft with it.\n" );
}
}

AND_WHEN( "they acquire the needed skill" ) {
g->u.set_skill_level( purtab->skill_used, purtab->difficulty );

REQUIRE( g->u.get_skill_level( purtab->skill_used ) == purtab->difficulty );
REQUIRE_FALSE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) );

THEN( "still nothing is craftable from it" ) {
iteminfo_test(
iodine, q,
"--\nYou know of nothing you could craft with it.\n" );
}

AND_WHEN( "they have the water purification tablet recipe memorized" ) {
item &textbook = character.i_add( item( "textbook_chemistry" ) );
character.set_skill_level( pur->skill_used, pur->difficulty + 1 );
character.learn_recipe( pur );
REQUIRE( character.knows_recipe( pur ) );
WHEN( "they have no book, but have the recipe memorized" ) {
g->u.learn_recipe( purtab );

REQUIRE( g->u.knows_recipe( purtab ) );
REQUIRE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) );

THEN( "they can use potassium iodide tablets to craft it" ) {
std::vector<iteminfo> info_v;
std::string info = iodine.info( info_v, &q, 1 );
CHECK( info == "--\n"
"You could use it to craft: "
"<color_c_dark_gray>water purification tablet</color>\n" );
iteminfo_test(
iodine, q,
"--\n"
"You could use it to craft: "
"<color_c_dark_gray>water purification tablet</color>\n" );
}
}
}

WHEN( "they have the recipe in a book, but not memorized" ) {
item &book = g->u.i_add( item( "textbook_chemistry" ) );
g->u.do_read( book );

REQUIRE_FALSE( g->u.knows_recipe( purtab ) );
REQUIRE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) );

THEN( "they can use potassium iodide tablets to craft it" ) {
iteminfo_test(
iodine, q,
"--\n"
"You could use it to craft: "
"<color_c_dark_gray>water purification tablet</color>\n" );
}
}
}
}
}

0 comments on commit 3561ef3

Please sign in to comment.