-
Notifications
You must be signed in to change notification settings - Fork 280
/
food_fun_for_test.cpp
306 lines (249 loc) · 9.86 KB
/
food_fun_for_test.cpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include "catch/catch.hpp"
#include <cstdlib>
#include <utility>
#include "avatar.h"
#include "calendar.h"
#include "flag.h"
#include "item.h"
#include "itype.h"
#include "player_helpers.h"
#include "type_id.h"
#include "units.h"
#include "morale_types.h"
static const bionic_id bio_taste_blocker( "bio_taste_blocker" );
static const trait_id trait_THRESH_FELINE( "THRESH_FELINE" );
static const trait_id trait_THRESH_LUPINE( "THRESH_LUPINE" );
// Test cases for `Character::fun_for` defined in `src/consumption.cpp`
TEST_CASE( "fun for non-food", "[fun_for][nonfood]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
SECTION( "non-food has no fun value" ) {
item &rag = *item::spawn_temporary( "rag" );
REQUIRE_FALSE( rag.is_comestible() );
actual_fun = dummy.fun_for( rag );
CHECK( actual_fun.first == 0 );
CHECK( actual_fun.second == 0 );
}
}
TEST_CASE( "fun for rotten food", "[fun_for][food][rotten]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
GIVEN( "some rotten food" ) {
item &nuts = *item::spawn_temporary( "almond_milk" );
REQUIRE( nuts.is_comestible() );
// food rot > 1.0 is rotten
nuts.set_relative_rot( 1.5 );
REQUIRE( nuts.rotten() );
WHEN( "character has normal tastes" ) {
REQUIRE_FALSE( dummy.has_trait( trait_id( "SAPROPHAGE" ) ) );
REQUIRE_FALSE( dummy.has_trait( trait_id( "SAPROVORE" ) ) );
THEN( "they don't like rotten food" ) {
actual_fun = dummy.fun_for( nuts );
CHECK( actual_fun.first < 0 );
}
}
WHEN( "character is a saprophage" ) {
dummy.toggle_trait( trait_id( "SAPROPHAGE" ) );
REQUIRE( dummy.has_trait( trait_id( "SAPROPHAGE" ) ) );
THEN( "they like rotten food" ) {
actual_fun = dummy.fun_for( nuts );
CHECK( actual_fun.first > 0 );
}
}
WHEN( "character is a saprovore" ) {
dummy.toggle_trait( trait_id( "SAPROVORE" ) );
REQUIRE( dummy.has_trait( trait_id( "SAPROVORE" ) ) );
THEN( "they like rotten food" ) {
actual_fun = dummy.fun_for( nuts );
CHECK( actual_fun.first > 0 );
}
}
}
}
TEST_CASE( "fun for cat food", "[fun_for][food][cat][feline]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
GIVEN( "cat food" ) {
item &catfood = *item::spawn_temporary( "catfood" );
REQUIRE( catfood.is_comestible() );
REQUIRE( catfood.has_flag( flag_FELINE ) );
WHEN( "character is not feline" ) {
REQUIRE_FALSE( dummy.has_trait( trait_THRESH_FELINE ) );
THEN( "they dislike cat food" ) {
actual_fun = dummy.fun_for( catfood );
CHECK( actual_fun.first < 0 );
}
}
WHEN( "character is feline" ) {
dummy.toggle_trait( trait_THRESH_FELINE );
REQUIRE( dummy.has_trait( trait_THRESH_FELINE ) );
THEN( "they like cat food" ) {
actual_fun = dummy.fun_for( catfood );
CHECK( actual_fun.first > 0 );
}
WHEN( "cat food is rotten" ) {
// food rot > 1.0 is rotten
catfood.set_relative_rot( 1.5 );
REQUIRE( catfood.rotten() );
THEN( "they dislike rotten cat food" ) {
actual_fun = dummy.fun_for( catfood );
CHECK( actual_fun.first < 0 );
}
}
}
}
}
TEST_CASE( "fun for dog food", "[fun_for][food][dog][lupine]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
GIVEN( "dog food" ) {
item &dogfood = *item::spawn_temporary( "dogfood" );
REQUIRE( dogfood.is_comestible() );
REQUIRE( dogfood.has_flag( flag_LUPINE ) );
WHEN( "character is not lupine" ) {
REQUIRE_FALSE( dummy.has_trait( trait_THRESH_LUPINE ) );
THEN( "they dislike dog food" ) {
actual_fun = dummy.fun_for( dogfood );
CHECK( actual_fun.first < 0 );
}
}
WHEN( "character is lupine" ) {
dummy.toggle_trait( trait_THRESH_LUPINE );
REQUIRE( dummy.has_trait( trait_THRESH_LUPINE ) );
THEN( "they like dog food" ) {
actual_fun = dummy.fun_for( dogfood );
CHECK( actual_fun.first > 0 );
}
WHEN( "dog food is rotten" ) {
// food rot > 1.0 is rotten
dogfood.set_relative_rot( 1.5 );
REQUIRE( dogfood.rotten() );
THEN( "they dislike rotten dog food" ) {
actual_fun = dummy.fun_for( dogfood );
CHECK( actual_fun.first < 0 );
}
}
}
}
}
TEST_CASE( "fun for gourmand", "[fun_for][food][gourmand]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
GIVEN( "food that tastes good" ) {
item &toastem = *item::spawn_temporary( "toastem" );
REQUIRE( toastem.is_comestible() );
int toastem_fun = toastem.get_comestible_fun();
REQUIRE( toastem_fun > 0 );
WHEN( "character is not a gourmand" ) {
REQUIRE_FALSE( dummy.has_trait( trait_id( "GOURMAND" ) ) );
THEN( "it tastes just as good as normal" ) {
actual_fun = dummy.fun_for( toastem );
CHECK( actual_fun.first == toastem_fun );
}
}
WHEN( "character is a gourmand" ) {
dummy.toggle_trait( trait_id( "GOURMAND" ) );
REQUIRE( dummy.has_trait( trait_id( "GOURMAND" ) ) );
THEN( "it tastes better than normal" ) {
actual_fun = dummy.fun_for( toastem );
CHECK( actual_fun.first > toastem_fun );
}
}
}
GIVEN( "food that tastes bad" ) {
item &garlic = *item::spawn_temporary( "garlic" );
REQUIRE( garlic.is_comestible() );
int garlic_fun = garlic.get_comestible_fun();
// At fun == -1, Gourmand trait has no effect
REQUIRE( garlic_fun < -1 );
WHEN( "character is not a gourmand" ) {
REQUIRE_FALSE( dummy.has_trait( trait_id( "GOURMAND" ) ) );
THEN( "it tastes just as bad as normal" ) {
actual_fun = dummy.fun_for( garlic );
CHECK( actual_fun.first == garlic_fun );
}
}
WHEN( "character is a gourmand" ) {
dummy.toggle_trait( trait_id( "GOURMAND" ) );
REQUIRE( dummy.has_trait( trait_id( "GOURMAND" ) ) );
THEN( "it still tastes bad, but not as bad as normal" ) {
actual_fun = dummy.fun_for( garlic );
CHECK( actual_fun.first > garlic_fun );
}
}
}
}
TEST_CASE( "fun for food eaten too often", "[fun_for][food][monotony]" )
{
avatar dummy;
std::pair<int, int> actual_fun;
// A big box of tasty toast-ems
item &toastem = *item::spawn_temporary( "toastem", calendar::turn, 10 );
REQUIRE( toastem.is_comestible() );
// Base fun value and monotony penalty for toast-em
int toastem_fun = toastem.get_comestible_fun();
int toastem_penalty = toastem.get_comestible()->monotony_penalty;
// Will do 2 rounds of penalty testing, so base fun needs to be at least 2x that
REQUIRE( toastem_fun > 2 * toastem_penalty );
GIVEN( "food that is fun to eat" ) {
WHEN( "character has not had any recently" ) {
THEN( "it tastes as good as it should" ) {
actual_fun = dummy.fun_for( toastem );
CHECK( actual_fun.first == toastem_fun );
}
}
WHEN( "character has just eaten one" ) {
dummy.eat( toastem );
THEN( "the next one is less enjoyable" ) {
actual_fun = dummy.fun_for( toastem );
CHECK( actual_fun.first == toastem_fun - toastem_penalty );
}
AND_WHEN( "character has eaten another one" ) {
dummy.eat( toastem );
THEN( "the one after that is even less enjoyable" ) {
actual_fun = dummy.fun_for( toastem );
CHECK( actual_fun.first == toastem_fun - 2 * toastem_penalty );
}
}
}
}
}
TEST_CASE( "fun for bionic bio taste blocker", "[fun_for][food][bionic]" )
{
avatar dummy;
GIVEN( "food that tastes bad" ) {
item &garlic = *item::spawn_temporary( "garlic" );
REQUIRE( garlic.is_comestible() );
int garlic_fun = garlic.get_comestible_fun();
REQUIRE( garlic_fun < 0 );
AND_GIVEN( "character has a taste modifier CBM" ) {
dummy.set_max_power_level( 1000_kJ );
give_and_activate_bionic( dummy, bionic_id( "bio_taste_blocker" ) );
REQUIRE( dummy.has_active_bionic( bio_taste_blocker ) );
WHEN( "it does not have enough power" ) {
// Needs 1 kJ per negative fun unit to nullify bad taste
dummy.set_power_level( 10_kJ );
REQUIRE( garlic_fun < -10 );
REQUIRE_FALSE( dummy.get_power_level() > units::from_kilojoule( std::abs( garlic_fun ) ) );
THEN( "the bad taste remains" ) {
dummy.eat( garlic );
CHECK( dummy.get_morale( MORALE_FOOD_BAD ) == garlic_fun );
}
}
WHEN( "it has enough power" ) {
REQUIRE( garlic_fun >= -20 );
dummy.set_power_level( 20_kJ );
REQUIRE( dummy.get_power_level() > units::from_kilojoule( std::abs( garlic_fun ) ) );
THEN( "the bad taste is nullified" ) {
dummy.eat( garlic );
CHECK( dummy.get_morale( MORALE_FOOD_BAD ) == 0 );
}
}
}
}
}