void merge_invlet_test( player &dummy, inventory_location from ) { // invlet to assign constexpr char invlet_1 = '{'; constexpr char invlet_2 = '}'; // should merge from a place other than the inventory REQUIRE( from != INVENTORY ); // cannot assign invlet to items on the ground REQUIRE( from != GROUND ); for( int id = 0; id < INVLET_STATE_NUM * INVLET_STATE_NUM; ++id ) { // how to assign invlet to the first item invlet_state first_invlet_state = invlet_state( id % INVLET_STATE_NUM ); // how to assign invlet to the second item invlet_state second_invlet_state = invlet_state( id / INVLET_STATE_NUM ); // what the invlet should be for the merged stack invlet_state expected_merged_invlet_state = first_invlet_state != NONE ? first_invlet_state : second_invlet_state; char expected_merged_invlet = first_invlet_state != NONE ? invlet_1 : second_invlet_state != NONE ? invlet_2 : 0; // remove all items dummy.inv.clear(); dummy.worn.clear(); dummy.remove_weapon(); g->m.i_clear( dummy.pos() ); // some stackable item item tshirt( "tshirt" ); // add the item add_item( dummy, tshirt, INVENTORY ); add_item( dummy, tshirt, from ); // assign the items with invlets assign_invlet( dummy, item_at( dummy, 0, INVENTORY ), invlet_1, first_invlet_state ); assign_invlet( dummy, item_at( dummy, 0, from ), invlet_2, second_invlet_state ); // merge the second item into inventory move_item( dummy, 0, from, INVENTORY ); item &merged_item = item_at( dummy, 0, INVENTORY ); invlet_state merged_invlet_state = check_invlet( dummy, merged_item, expected_merged_invlet ); char merged_invlet = merged_item.invlet; std::stringstream ss; ss << "1. add two stackable items to the inventory and " << location_desc( from ) << std::endl; ss << "2. assign " << invlet_state_desc( first_invlet_state ) << " invlet " << invlet_1 << " to the item in the inventory " << std::endl; ss << "3. assign " << invlet_state_desc( second_invlet_state ) << " invlet " << invlet_2 << " to the " << location_desc( from ) << std::endl; ss << "4. " << move_action_desc( 0, from, INVENTORY ) << std::endl; ss << "expect the stack in the inventory to have " << invlet_state_desc( expected_merged_invlet_state ) << " invlet " << expected_merged_invlet << std::endl; ss << "the stack actually has " << invlet_state_desc( merged_invlet_state ) << " invlet " << merged_invlet << std::endl; INFO( ss.str() ); REQUIRE( merged_item.typeId() == tshirt.typeId() ); CHECK( merged_invlet_state == expected_merged_invlet_state ); CHECK( merged_invlet == expected_merged_invlet ); } }
void swap_invlet_test( player &dummy, inventory_location loc ) { // invlet to assign constexpr char invlet_1 = '{'; constexpr char invlet_2 = '}'; // cannot swap invlets of items on the ground REQUIRE( loc != GROUND ); // remove all items dummy.inv.clear(); dummy.worn.clear(); dummy.remove_weapon(); g->m.i_clear( dummy.pos() ); // two items of the same type that do not stack item tshirt1( "tshirt" ); item tshirt2( "tshirt" ); tshirt2.mod_damage( -1 ); // add the items add_item( dummy, tshirt1, loc ); add_item( dummy, tshirt2, loc ); // assign the items with invlets assign_invlet( dummy, item_at( dummy, 0, loc ), invlet_1, CACHED ); assign_invlet( dummy, item_at( dummy, 1, loc ), invlet_2, CACHED ); // swap the invlets (invoking twice to make the invlet non-player-assigned) dummy.reassign_item( item_at( dummy, 0, loc ), invlet_2 ); dummy.reassign_item( item_at( dummy, 0, loc ), invlet_2 ); // drop the items move_item( dummy, 0, loc, GROUND ); move_item( dummy, 0, loc, GROUND ); // get them again move_item( dummy, 0, GROUND, loc ); move_item( dummy, 0, GROUND, loc ); std::stringstream ss; ss << "1. add two items of the same type to " << location_desc( loc ) << ", and ensure them do not stack" << std::endl; ss << "2. assign different invlets to the two items" << std::endl; ss << "3. swap the invlets by assign one of the items with the invlet of the other item" << std::endl; ss << "4. move the items to " << location_desc( GROUND ) << std::endl; ss << "5. move the items to " << location_desc( loc ) << " again" << std::endl; ss << "expect the items to keep their swapped invlets" << std::endl; if( item_at( dummy, 0, loc ).invlet == invlet_2 && item_at( dummy, 1, loc ).invlet == invlet_1 ) { ss << "the items actually keep their swapped invlets" << std::endl; } else { ss << "the items actually does not keep their swapped invlets" << std::endl; } INFO( ss.str() ); REQUIRE( item_at( dummy, 0, loc ).typeId() == tshirt1.typeId() ); REQUIRE( item_at( dummy, 1, loc ).typeId() == tshirt2.typeId() ); // invlets should not disappear and should still be swapped CHECK( item_at( dummy, 0, loc ).invlet == invlet_2 ); CHECK( item_at( dummy, 1, loc ).invlet == invlet_1 ); CHECK( check_invlet( dummy, item_at( dummy, 0, loc ), invlet_2 ) == CACHED ); CHECK( check_invlet( dummy, item_at( dummy, 1, loc ), invlet_1 ) == CACHED ); // clear invlets assign_invlet( dummy, item_at( dummy, 0, loc ), invlet_2, NONE ); assign_invlet( dummy, item_at( dummy, 1, loc ), invlet_1, NONE ); }
void invlet_test( player &dummy, inventory_location from, inventory_location to ) { // invlet to assign constexpr char invlet = '|'; // iterate through all permutations of test actions for( int id = 0; id < INVLET_STATE_NUM * INVLET_STATE_NUM * TEST_ACTION_NUM; ++id ) { // how to assign invlet to the first item invlet_state first_invlet_state = invlet_state( id % INVLET_STATE_NUM ); // how to assign invlet to the second item invlet_state second_invlet_state = invlet_state( id / INVLET_STATE_NUM % INVLET_STATE_NUM ); // the test steps test_action action = test_action( id / INVLET_STATE_NUM / INVLET_STATE_NUM % TEST_ACTION_NUM ); // the final expected invlet state of the two items invlet_state expected_first_invlet_state = second_invlet_state == NONE ? first_invlet_state : NONE; invlet_state expected_second_invlet_state = second_invlet_state; // remove all items dummy.inv.clear(); dummy.worn.clear(); dummy.remove_weapon(); g->m.i_clear( dummy.pos() ); // some two items that can be wielded, worn, and picked up item tshirt( "tshirt" ); item jeans( "jeans" ); // add the items to the starting position add_item( dummy, tshirt, to ); add_item( dummy, jeans, to ); // assign invlet to the first item assign_invlet( dummy, item_at( dummy, 0, to ), invlet, first_invlet_state ); // remove the first item move_item( dummy, 0, to, from ); // assign invlet to the second item assign_invlet( dummy, item_at( dummy, 0, to ), invlet, second_invlet_state ); item *final_first = nullptr, *final_second = nullptr; switch( action ) { case REMOVE_1ST_REMOVE_2ND_ADD_1ST_ADD_2ND: move_item( dummy, 0, to, from ); move_item( dummy, 0, from, to ); move_item( dummy, 0, from, to ); final_first = &item_at( dummy, 0, to ); final_second = &item_at( dummy, 1, to ); break; case REMOVE_1ST_REMOVE_2ND_ADD_2ND_ADD_1ST: move_item( dummy, 0, to, from ); move_item( dummy, 1, from, to ); move_item( dummy, 0, from, to ); final_first = &item_at( dummy, 1, to ); final_second = &item_at( dummy, 0, to ); break; case REMOVE_1ST_ADD_1ST: move_item( dummy, 0, from, to ); final_first = &item_at( dummy, 1, to ); final_second = &item_at( dummy, 0, to ); break; default: FAIL( "unimplemented" ); break; } invlet_state final_first_invlet_state = check_invlet( dummy, *final_first, invlet ), final_second_invlet_state = check_invlet( dummy, *final_second, invlet ); INFO( test_action_desc( action, from, to, first_invlet_state, second_invlet_state, expected_first_invlet_state, expected_second_invlet_state, final_first_invlet_state, final_second_invlet_state ) ); REQUIRE( final_first->typeId() == tshirt.typeId() ); REQUIRE( final_second->typeId() == jeans.typeId() ); CHECK( final_first_invlet_state == expected_first_invlet_state ); CHECK( final_second_invlet_state == expected_second_invlet_state ); // clear invlets assign_invlet( dummy, *final_first, invlet, NONE ); assign_invlet( dummy, *final_second, invlet, NONE ); } }