1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#include <cstddef>
#include <iosfwd>
#include <string>
#include <vector>
#include "cata_catch.h"
#include "make_static.h"
#include "requirements.h"
#include "type_id.h"
static const itype_id itype_ash( "ash" );
static const itype_id itype_chem_sulphuric_acid( "chem_sulphuric_acid" );
static const itype_id itype_lye( "lye" );
static const itype_id itype_rock( "rock" );
static const itype_id itype_soap( "soap" );
static const itype_id itype_yarn( "yarn" );
static const requirement_id requirement_data_eggs_bird( "eggs_bird" );
static const requirement_id
requirement_data_explosives_casting_standard( "explosives_casting_standard" );
static void test_requirement_deduplication(
const requirement_data::alter_item_comp_vector &before,
std::vector<requirement_data::alter_item_comp_vector> after
)
{
requirement_data in( {}, {}, before );
deduped_requirement_data out( in, recipe_id::NULL_ID() );
CHECK( out.alternatives().size() == after.size() );
while( after.size() < out.alternatives().size() ) {
after.emplace_back();
}
for( size_t i = 0; i < out.alternatives().size(); ++i ) {
CAPTURE( i );
requirement_data this_expected( {}, {}, after[i] );
CHECK( out.alternatives()[i].list_all() == this_expected.list_all() );
}
}
TEST_CASE( "simple_requirements_dont_multiply", "[requirement]" )
{
test_requirement_deduplication( { { { itype_rock, 1 } } }, { { { { itype_rock, 1 } } } } );
}
TEST_CASE( "survivor_telescope_inspired_example", "[requirement]" )
{
test_requirement_deduplication(
{ { { itype_rock, 1 }, { itype_soap, 1 } }, { { itype_rock, 1 } } }, {
{ { { itype_soap, 1 } }, { { itype_rock, 1 } } },
{ { { itype_rock, 2 } } }
} );
}
TEST_CASE( "survivor_telescope_inspired_example_2", "[requirement]" )
{
test_requirement_deduplication(
{ { { itype_ash, 1 } }, { { itype_rock, 1 }, { itype_soap, 1 } }, { { itype_rock, 1 } }, { { itype_lye, 1 } } }, {
{ { { itype_ash, 1 } }, { { itype_soap, 1 } }, { { itype_rock, 1 } }, { { itype_lye, 1 } } },
{ { { itype_ash, 1 } }, { { itype_rock, 2 } }, { { itype_lye, 1 } } }
} );
}
TEST_CASE( "woods_soup_inspired_example", "[requirement]" )
{
test_requirement_deduplication(
{ { { itype_rock, 1 }, { itype_soap, 1 } }, { { itype_rock, 1 }, { itype_yarn, 1 } } }, {
{ { { itype_soap, 1 } }, { { itype_rock, 1 }, { itype_yarn, 1 } } },
{ { { itype_rock, 1 } }, { { itype_yarn, 1 } } },
{ { { itype_rock, 2 } } }
} );
}
TEST_CASE( "triple_overlap_1", "[requirement]" )
{
test_requirement_deduplication( {
{ { itype_rock, 1 }, { itype_soap, 1 } },
{ { itype_rock, 1 } },
{ { itype_soap, 1 } }
}, {
{ { { itype_rock, 1 } }, { { itype_soap, 2 } } },
{ { { itype_rock, 2 } }, { { itype_soap, 1 } } },
} );
}
TEST_CASE( "triple_overlap_2", "[requirement]" )
{
test_requirement_deduplication( {
{ { itype_rock, 1 }, { itype_soap, 1 } },
{ { itype_rock, 1 }, { itype_yarn, 1 } },
{ { itype_soap, 1 }, { itype_chem_sulphuric_acid, 1 } }
}, {
{ { { itype_soap, 1 } }, { { itype_rock, 1 }, { itype_yarn, 1 } }, { { itype_chem_sulphuric_acid, 1 } } },
{ { { itype_rock, 1 }, { itype_yarn, 1 } }, { { itype_soap, 2 } } },
{ { { itype_rock, 1 } }, { { itype_yarn, 1 } }, { { itype_chem_sulphuric_acid, 1 }, { itype_soap, 1 } } },
{ { { itype_rock, 2 } }, { { itype_chem_sulphuric_acid, 1 }, { itype_soap, 1 } } },
} );
}
TEST_CASE( "triple_overlap_3", "[requirement]" )
{
test_requirement_deduplication( {
{ { itype_rock, 1 }, { itype_soap, 1 } },
{ { itype_rock, 1 }, { itype_yarn, 1 } },
{ { itype_soap, 1 }, { itype_yarn, 1 } }
}, {
// These results are not ideal. Two of them are equivalent and
// another two could be merged. But they are correct, and that
// seems good enough for now. I don't anticipate any real recipes
// being as complicated to resolve as this one.
{ { { itype_soap, 1 } }, { { itype_rock, 1 } }, { { itype_yarn, 1 } } },
{ { { itype_soap, 1 } }, { { itype_yarn, 2 } } },
{ { { itype_rock, 1 }, { itype_yarn, 1 } }, { { itype_soap, 2 } } },
{ { { itype_rock, 1 } }, { { itype_yarn, 1 } }, { { itype_soap, 1 } } },
{ { { itype_rock, 1 } }, { { itype_yarn, 2 } } },
{ { { itype_rock, 2 } }, { { itype_yarn, 1 }, { itype_soap, 1 } } },
} );
}
TEST_CASE( "deduplicate_repeated_requirements", "[requirement]" )
{
test_requirement_deduplication( {
{ { itype_rock, 1 } }, { { itype_yarn, 1 } }, { { itype_rock, 1 } }, { { itype_yarn, 1 } }
}, {
{ { { itype_rock, 2 } }, { { itype_yarn, 2 } } },
} );
}
TEST_CASE( "requirement_extension", "[requirement]" )
{
SECTION( "basic_component_extension" ) {
const std::vector<std::vector<item_comp>> &req_comp = requirement_data_eggs_bird->get_components();
REQUIRE( !req_comp.empty() );
REQUIRE( req_comp.size() == 1 );
REQUIRE( req_comp.front().size() > 1 );
bool found_extended_comp = false;
for( const item_comp &comp : req_comp[0] ) {
if( comp.type == STATIC( itype_id( "test_egg" ) ) ) {
found_extended_comp = true;
CHECK( comp.count == 2 );
}
}
CHECK( found_extended_comp );
}
SECTION( "multigroup_tool_extension" ) {
const std::vector<std::vector<tool_comp>> &req_tool =
requirement_data_explosives_casting_standard->get_tools();
REQUIRE( !req_tool.empty() );
REQUIRE( req_tool.size() == 2 );
REQUIRE( req_tool[0].size() > 1 );
REQUIRE( req_tool[1].size() > 3 );
std::vector<std::map<const itype_id, bool>> found_itype_maps = {
{
{ STATIC( itype_id( "metal_tank_test" ) ), false }
},
{
{ STATIC( itype_id( "test_pipe" ) ), false },
{ STATIC( itype_id( "test_glass_pipe_mostly_steel" ) ), false },
{ STATIC( itype_id( "test_glass_pipe_mostly_glass" ) ), false }
}
};
for( int i = 0; i < static_cast<int>( req_tool.size() ); i++ ) {
for( const tool_comp &tool : req_tool[i] ) {
for( std::pair<const itype_id, bool> &f : found_itype_maps[i] ) {
if( tool.type == f.first ) {
f.second = true;
}
}
}
}
for( const std::map<const itype_id, bool> &f : found_itype_maps ) {
for( const std::pair<const itype_id, bool> &found : f ) {
CAPTURE( found.first.c_str() );
CHECK( found.second );
}
}
}
}
|