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
|
#include "catch/catch.hpp"
#include "calendar.h"
#include "itype.h"
#include "ret_val.h"
#include "units.h"
#include "item.h"
TEST_CASE( "item_volume", "[item]" )
{
// Need to pick some item here which is count_by_charges and for which each
// charge is at least 1_ml. Battery works for now.
item i( "battery", 0, item::default_charges_tag() );
REQUIRE( i.count_by_charges() );
// Would be better with Catch2 generators
const units::volume big_volume = units::from_milliliter( std::numeric_limits<int>::max() / 2 );
for( units::volume v : {
0_ml, 1_ml, i.volume(), big_volume
} ) {
INFO( "checking batteries that fit in " << v );
const long charges_that_should_fit = i.charges_per_volume( v );
i.charges = charges_that_should_fit;
CHECK( i.volume() <= v ); // this many charges should fit
i.charges++;
CHECK( i.volume() > v ); // one more charge should not fit
}
}
TEST_CASE( "simple_item_layers", "[item]" )
{
CHECK( item( "arm_warmers" ).get_layer() == UNDERWEAR );
CHECK( item( "10gal_hat" ).get_layer() == REGULAR_LAYER );
CHECK( item( "baldric" ).get_layer() == WAIST_LAYER );
CHECK( item( "aep_suit" ).get_layer() == OUTER_LAYER );
CHECK( item( "2byarm_guard" ).get_layer() == BELTED_LAYER );
}
TEST_CASE( "gun_layer", "[item]" )
{
item gun( "win70" );
item mod( "shoulder_strap" );
CHECK( gun.is_gunmod_compatible( mod ).success() );
gun.contents.push_back( mod );
CHECK( gun.get_layer() == BELTED_LAYER );
}
// second minute hour day week season year
TEST_CASE( "stacking_over_time", "[item]" )
{
item A( "neccowafers" );
item B( "neccowafers" );
GIVEN( "Two items with the same birthday" ) {
REQUIRE( A.stacks_with( B ) );
WHEN( "the items are aged different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - 1_turns );
B.mod_rot( B.type->comestible->spoils - 3_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the minute but different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - 5_minutes );
B.mod_rot( B.type->comestible->spoils - 5_minutes );
B.mod_rot( -5_turns );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different minutes" ) {
A.mod_rot( A.type->comestible->spoils - 5_minutes );
B.mod_rot( B.type->comestible->spoils - 5_minutes );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the hour but different numbers of minutes" ) {
A.mod_rot( A.type->comestible->spoils - 5_hours );
B.mod_rot( B.type->comestible->spoils - 5_hours );
B.mod_rot( -5_minutes );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different hours" ) {
A.mod_rot( A.type->comestible->spoils - 5_hours );
B.mod_rot( B.type->comestible->spoils - 5_hours );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the day but different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - 3_days );
B.mod_rot( B.type->comestible->spoils - 3_days );
B.mod_rot( -5_turns );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different days" ) {
A.mod_rot( A.type->comestible->spoils - 3_days );
B.mod_rot( B.type->comestible->spoils - 3_days );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the week but different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - 7_days );
B.mod_rot( B.type->comestible->spoils - 7_days );
B.mod_rot( -5_turns );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different weeks" ) {
A.mod_rot( A.type->comestible->spoils - 7_days );
B.mod_rot( B.type->comestible->spoils - 7_days );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the season but different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - calendar::season_length() );
B.mod_rot( B.type->comestible->spoils - calendar::season_length() );
B.mod_rot( -5_turns );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different seasons" ) {
A.mod_rot( A.type->comestible->spoils - calendar::season_length() );
B.mod_rot( B.type->comestible->spoils - calendar::season_length() );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
WHEN( "the items are aged the same to the year but different numbers of seconds" ) {
A.mod_rot( A.type->comestible->spoils - calendar::year_length() );
B.mod_rot( B.type->comestible->spoils - calendar::year_length() );
B.mod_rot( -5_turns );
THEN( "they stack" ) {
CHECK( A.stacks_with( B ) );
}
}
WHEN( "the items are aged a few seconds different but different years" ) {
A.mod_rot( A.type->comestible->spoils - calendar::year_length() );
B.mod_rot( B.type->comestible->spoils - calendar::year_length() );
B.mod_rot( 5_turns );
THEN( "they don't stack" ) {
CHECK( !A.stacks_with( B ) );
}
}
}
}
|