forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreading_test.cpp
341 lines (277 loc) · 12 KB
/
reading_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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#include "catch/catch.hpp"
#include <memory>
#include <string>
#include <vector>
#include "avatar.h"
#include "bodypart.h"
#include "calendar.h"
#include "debug.h"
#include "item.h"
#include "itype.h"
#include "morale_types.h"
#include "type_id.h"
#include "value_ptr.h"
class player;
static const trait_id trait_HATES_BOOKS( "HATES_BOOKS" );
static const trait_id trait_HYPEROPIC( "HYPEROPIC" );
static const trait_id trait_ILLITERATE( "ILLITERATE" );
static const trait_id trait_LOVES_BOOKS( "LOVES_BOOKS" );
static const trait_id trait_SPIRITUAL( "SPIRITUAL" );
TEST_CASE( "identifying unread books", "[reading][book][identify]" )
{
avatar dummy;
dummy.worn.push_back( item( "backpack" ) );
GIVEN( "player has some unidentified books" ) {
item &book1 = dummy.i_add( item( "novel_western" ) );
item &book2 = dummy.i_add( item( "mag_throwing" ) );
REQUIRE_FALSE( dummy.has_identified( book1.typeId() ) );
REQUIRE_FALSE( dummy.has_identified( book2.typeId() ) );
WHEN( "they read the books for the first time" ) {
dummy.do_read( book1 );
dummy.do_read( book2 );
THEN( "the books should be identified" ) {
CHECK( dummy.has_identified( book1.typeId() ) );
CHECK( dummy.has_identified( book2.typeId() ) );
}
}
}
}
TEST_CASE( "reading a book for fun", "[reading][book][fun]" )
{
avatar dummy;
dummy.set_body();
dummy.worn.push_back( item( "backpack" ) );
GIVEN( "a fun book" ) {
item &book = dummy.i_add( item( "novel_western" ) );
REQUIRE( book.type->book );
REQUIRE( book.type->book->fun > 0 );
int book_fun = book.type->book->fun;
WHEN( "player neither loves nor hates books" ) {
REQUIRE_FALSE( dummy.has_trait( trait_LOVES_BOOKS ) );
REQUIRE_FALSE( dummy.has_trait( trait_HATES_BOOKS ) );
THEN( "the book is a normal amount of fun" ) {
CHECK( dummy.fun_to_read( book ) == true );
CHECK( dummy.book_fun_for( book, dummy ) == book_fun );
}
}
WHEN( "player loves books" ) {
dummy.toggle_trait( trait_LOVES_BOOKS );
REQUIRE( dummy.has_trait( trait_LOVES_BOOKS ) );
THEN( "the book is extra fun" ) {
CHECK( dummy.fun_to_read( book ) == true );
CHECK( dummy.book_fun_for( book, dummy ) == book_fun + 1 );
}
}
WHEN( "player hates books" ) {
dummy.toggle_trait( trait_HATES_BOOKS );
REQUIRE( dummy.has_trait( trait_HATES_BOOKS ) );
THEN( "the book is no fun at all" ) {
CHECK( dummy.fun_to_read( book ) == false );
CHECK( dummy.book_fun_for( book, dummy ) == 0 );
}
}
}
GIVEN( "a fun book that is also inspirational" ) {
item &book = dummy.i_add( item( "holybook_pastafarian" ) );
REQUIRE( book.has_flag( "INSPIRATIONAL" ) );
REQUIRE( book.type->book );
REQUIRE( book.type->book->fun > 0 );
int book_fun = book.type->book->fun;
WHEN( "player is not spiritual" ) {
REQUIRE_FALSE( dummy.has_trait( trait_SPIRITUAL ) );
THEN( "the book is a normal amount of fun" ) {
CHECK( dummy.fun_to_read( book ) == true );
CHECK( dummy.book_fun_for( book, dummy ) == book_fun );
}
}
WHEN( "player is spiritual" ) {
dummy.toggle_trait( trait_SPIRITUAL );
REQUIRE( dummy.has_trait( trait_SPIRITUAL ) );
THEN( "the book is thrice the fun" ) {
CHECK( dummy.fun_to_read( book ) == true );
CHECK( dummy.book_fun_for( book, dummy ) == book_fun * 3 );
}
}
}
}
TEST_CASE( "character reading speed", "[reading][character][speed]" )
{
avatar dummy;
dummy.worn.push_back( item( "backpack" ) );
// Note: read_speed() returns number of moves;
// 6000 == 60 seconds
WHEN( "player has average intelligence" ) {
REQUIRE( dummy.get_int() == 8 );
THEN( "reading speed is normal" ) {
CHECK( dummy.read_speed() == 6000 );
}
}
WHEN( "player has below-average intelligence" ) {
THEN( "reading speed gets slower as intelligence decreases" ) {
dummy.int_max = 7;
CHECK( dummy.read_speed() == 6300 );
dummy.int_max = 6;
CHECK( dummy.read_speed() == 6600 );
dummy.int_max = 5;
CHECK( dummy.read_speed() == 6900 );
dummy.int_max = 4;
CHECK( dummy.read_speed() == 7200 );
}
}
WHEN( "player has above-average intelligence" ) {
THEN( "reading speed gets faster as intelligence increases" ) {
dummy.int_max = 9;
CHECK( dummy.read_speed() == 5700 );
dummy.int_max = 10;
CHECK( dummy.read_speed() == 5400 );
dummy.int_max = 12;
CHECK( dummy.read_speed() == 4800 );
dummy.int_max = 14;
CHECK( dummy.read_speed() == 4200 );
}
}
}
TEST_CASE( "estimated reading time for a book", "[reading][book][time]" )
{
avatar dummy;
dummy.worn.push_back( item( "backpack" ) );
// Easy, medium, and hard books
item &child = dummy.i_add( item( "child_book" ) );
item &western = dummy.i_add( item( "novel_western" ) );
item &alpha = dummy.i_add( item( "recipe_alpha" ) );
// Ensure the books are actually books
REQUIRE( child.type->book );
REQUIRE( western.type->book );
REQUIRE( alpha.type->book );
// Convert time to read from minutes to moves, for easier comparison later
int moves_child = child.type->book->time * to_moves<int>( 1_minutes );
int moves_western = western.type->book->time * to_moves<int>( 1_minutes );
int moves_alpha = alpha.type->book->time * to_moves<int>( 1_minutes );
GIVEN( "some unidentified books and plenty of light" ) {
REQUIRE_FALSE( dummy.has_identified( child.typeId() ) );
REQUIRE_FALSE( dummy.has_identified( western.typeId() ) );
// Get some light
dummy.i_add( item( "atomic_lamp" ) );
REQUIRE( dummy.fine_detail_vision_mod() == 1 );
THEN( "identifying books takes 1/10th of the normal reading time" ) {
CHECK( dummy.time_to_read( western, dummy ) == moves_western / 10 );
CHECK( dummy.time_to_read( child, dummy ) == moves_child / 10 );
}
}
GIVEN( "some identified books and plenty of light" ) {
// Identify the books
dummy.do_read( child );
dummy.do_read( western );
dummy.do_read( alpha );
REQUIRE( dummy.has_identified( child.typeId() ) );
REQUIRE( dummy.has_identified( western.typeId() ) );
REQUIRE( dummy.has_identified( alpha.typeId() ) );
// Get some light
dummy.i_add( item( "atomic_lamp" ) );
REQUIRE( dummy.fine_detail_vision_mod() == 1 );
WHEN( "player has average intelligence" ) {
dummy.int_max = 8;
REQUIRE( dummy.get_int() == 8 );
REQUIRE( dummy.read_speed() == 6000 ); // 60s, "normal"
THEN( "they can read books at their reading level in the normal amount time" ) {
CHECK( dummy.time_to_read( child, dummy ) == moves_child );
CHECK( dummy.time_to_read( western, dummy ) == moves_western );
}
AND_THEN( "they can read books above their reading level, but it takes longer" ) {
CHECK( dummy.time_to_read( alpha, dummy ) > moves_alpha );
}
}
WHEN( "player has below average intelligence" ) {
dummy.int_max = 6;
REQUIRE( dummy.get_int() == 6 );
REQUIRE( dummy.read_speed() == 6600 ); // 66s
THEN( "they take longer than average to read any book" ) {
CHECK( dummy.time_to_read( child, dummy ) > moves_child );
CHECK( dummy.time_to_read( western, dummy ) > moves_western );
CHECK( dummy.time_to_read( alpha, dummy ) > moves_alpha );
}
}
WHEN( "player has above average intelligence" ) {
dummy.int_max = 10;
REQUIRE( dummy.get_int() == 10 );
REQUIRE( dummy.read_speed() == 5400 ); // 54s
THEN( "they take less time than average to read any book" ) {
CHECK( dummy.time_to_read( child, dummy ) < moves_child );
CHECK( dummy.time_to_read( western, dummy ) < moves_western );
CHECK( dummy.time_to_read( alpha, dummy ) < moves_alpha );
}
}
}
}
TEST_CASE( "reasons for not being able to read", "[reading][reasons]" )
{
avatar dummy;
dummy.set_body();
dummy.worn.push_back( item( "backpack" ) );
std::vector<std::string> reasons;
std::vector<std::string> expect_reasons;
item &child = dummy.i_add( item( "child_book" ) );
item &western = dummy.i_add( item( "novel_western" ) );
item &alpha = dummy.i_add( item( "recipe_alpha" ) );
SECTION( "you cannot read what is not readable" ) {
item &rag = dummy.i_add( item( "rag" ) );
REQUIRE_FALSE( rag.is_book() );
CHECK( dummy.get_book_reader( rag, reasons ) == nullptr );
expect_reasons = { "Your rag is not good reading material." };
CHECK( reasons == expect_reasons );
}
SECTION( "you cannot read in darkness" ) {
dummy.add_env_effect( efftype_id( "darkness" ), bodypart_id( "eyes" ), 3, 1_hours );
REQUIRE( dummy.fine_detail_vision_mod() > 4 );
CHECK( dummy.get_book_reader( child, reasons ) == nullptr );
expect_reasons = { "It's too dark to read!" };
CHECK( reasons == expect_reasons );
}
GIVEN( "some identified books and plenty of light" ) {
// Identify the books
dummy.do_read( child );
dummy.do_read( western );
dummy.do_read( alpha );
// Get some light
dummy.i_add( item( "atomic_lamp" ) );
REQUIRE( dummy.fine_detail_vision_mod() == 1 );
THEN( "you cannot read while illiterate" ) {
dummy.toggle_trait( trait_ILLITERATE );
REQUIRE( dummy.has_trait( trait_ILLITERATE ) );
CHECK( dummy.get_book_reader( western, reasons ) == nullptr );
expect_reasons = { "You're illiterate!" };
CHECK( reasons == expect_reasons );
}
THEN( "you cannot read while farsighted without reading glasses" ) {
dummy.toggle_trait( trait_HYPEROPIC );
REQUIRE( dummy.has_trait( trait_HYPEROPIC ) );
CHECK( dummy.get_book_reader( western, reasons ) == nullptr );
expect_reasons = { "Your eyes won't focus without reading glasses." };
CHECK( reasons == expect_reasons );
}
THEN( "you cannot read without enough skill to understand the book" ) {
dummy.set_skill_level( skill_id( "chemistry" ), 5 );
CHECK( dummy.get_book_reader( alpha, reasons ) == nullptr );
expect_reasons = { "chemistry 6 needed to understand. You have 5" };
CHECK( reasons == expect_reasons );
}
THEN( "you cannot read boring books when your morale is too low" ) {
dummy.add_morale( MORALE_FEELING_BAD, -50, -100 );
REQUIRE_FALSE( dummy.has_morale_to_read() );
CHECK( dummy.get_book_reader( alpha, reasons ) == nullptr );
expect_reasons = { "What's the point of studying? (Your morale is too low!)" };
CHECK( reasons == expect_reasons );
}
WHEN( "there is nothing preventing you from reading" ) {
REQUIRE_FALSE( dummy.has_trait( trait_ILLITERATE ) );
REQUIRE_FALSE( dummy.has_trait( trait_HYPEROPIC ) );
REQUIRE_FALSE( dummy.in_vehicle );
REQUIRE( dummy.has_morale_to_read() );
THEN( "you can read!" ) {
CHECK( dummy.get_book_reader( western, reasons ) != nullptr );
expect_reasons = {};
CHECK( reasons == expect_reasons );
}
}
}
}