diff --git a/tests/item_test.cpp b/tests/item_test.cpp index 3707b5fe01fd0..1844b096d1cd4 100644 --- a/tests/item_test.cpp +++ b/tests/item_test.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,7 +7,9 @@ #include "catch/catch.hpp" #include "enums.h" #include "item.h" +#include "item_factory.h" #include "itype.h" +#include "monstergenerator.h" #include "ret_val.h" #include "units.h" #include "value_ptr.h" @@ -157,3 +160,33 @@ TEST_CASE( "stacking_over_time", "[item]" ) } } } + +static void assert_minimum_length_to_volume_ratio( const item &target ) +{ + if( target.made_of( LIQUID ) || target.is_soft() ) { + // Nothing to assert about these. + return; + } + // Minimum possible length is if the item is a sphere. + const float minimal_diameter = std::cbrt( ( 3.0 * units::to_milliliter( target.volume() ) ) / + ( 4.0 * M_PI ) ); + CAPTURE( target.type->get_id() ); + CAPTURE( target.volume() ); + CHECK( units::to_centimeter( target.length() ) >= minimal_diameter ); +} + +TEST_CASE( "item length sanity check", "[item]" ) +{ + for( const itype *type : item_controller->all() ) { + const item sample( type ); + assert_minimum_length_to_volume_ratio( sample ); + } +} + +TEST_CASE( "corpse length sanity check", "[item]" ) +{ + for( const mtype &type : MonsterGenerator::generator().get_all_mtypes() ) { + const item sample = item::make_corpse( type.id ); + assert_minimum_length_to_volume_ratio( sample ); + } +}