Files
Cataclysm-DDA/tests/inventory_test.cpp
Curtis Merrill a9381f8785 move all crafting_inventory operations to temp_crafting_inventory class (#88606)
* move all crafting_inventory operations to temp_crafting_inventory class

* fix rebase errors

move some functions back to where they were

adjust operator=

use pseudo items and item_location in form_inventory

remove obsolete comment

* add pseudo item dedup

* check for empty item_location in visitable

* iterate over copies items as well

* pseudo item

* Update temp_crafting_inventory.cpp

* fix some compile errors

* Update craft_attention_test.cpp

* Update temp_crafting_inventory.cpp

* address clang_tidy

* dump non const

* Apply batched suggestions from code review

IWYU

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* IWYU

* IWYU

* clang

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-09-16 22:09:02 -05:00

55 lines
1.5 KiB
C++

#include <vector>
#include "calendar.h"
#include "cata_catch.h"
#include "coordinates.h"
#include "item.h"
#include "map.h"
#include "map_helpers.h"
#include "point.h"
#include "temp_crafting_inventory.h"
#include "type_id.h"
static const itype_id itype_rock( "rock" );
static const itype_id itype_stick( "stick" );
static const itype_id itype_string_36( "string_36" );
TEST_CASE( "inventory_form_from_map_bulk_batching", "[inventory][map]" )
{
clear_map_without_vision();
map &m = get_map();
// Set up item positions
tripoint_bub_ms p1( 0, 0, 0 );
tripoint_bub_ms p2( 1, 0, 0 );
tripoint_bub_ms p3( 2, 0, 0 );
// Add items to the map
item rock( itype_rock, calendar::turn );
item stick( itype_stick, calendar::turn );
item string( itype_string_36, calendar::turn );
for( int i = 0; i < 5; ++i ) {
m.add_item_or_charges( p1, rock );
m.add_item_or_charges( p1, stick );
m.add_item_or_charges( p1, stick ); // Extra stick
m.add_item_or_charges( p2, stick );
m.add_item_or_charges( p2, string );
m.add_item_or_charges( p3, rock );
}
std::vector<tripoint_bub_ms> pts = { p1, p2, p3 };
temp_crafting_inventory inv;
inv.form_from_map( m, pts, nullptr );
// Check counts
// Rocks: 5 at p1 + 5 at p3 = 10 rocks
// Sticks: 10 at p1 + 5 at p2 = 15 sticks
// Strings: 5 at p2 = 5 strings
CHECK( inv.count_item( itype_rock ) == 10 );
CHECK( inv.count_item( itype_stick ) == 15 );
CHECK( inv.count_item( itype_string_36 ) == 5 );
}