-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_colony_forecast.R
579 lines (521 loc) · 31.4 KB
/
test_colony_forecast.R
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#------------------------------------------------------------------------------
# (C) Crown Copyright 2025 Defence Science and Technology Laboratory UK
#
# Approval for wider use or release must be sought from:
# Intellectual Property Department
# Defence Science and Technology Laboratory
# Porton Down, Salisbury, Wiltshire, SP4 0JQ.
#
# The software/data, including any associated documentation, is supplied without
# warranty of performance, and in particular Dstl does not warrant, guarantee
# or make any representations regarding the use or the results of the use of the
# software in terms of currentness, accuracy, reliability, correctness,
# merchantability, fitness for purpose or otherwise.
#------------------------------------------------------------------------------
rm(list=ls()) # clear workspace
library(testthat) # this R package must be installed in order to run this script
#------------------------------------------------------------------------------
# USER INPUT: specify the working directory in which the model scripts are saved:
working_dir_path='insert/working/directory/path/here'
setwd(working_dir_path)
#------------------------------------------------------------------------------
# source model scripts:
source('./colony_forecast.R')
source('./helper_functions.R')
#------------------------------------------------------------------------------
# load dummy dataset for testing model arguments:
load('./tests/testing-dummydata.RData')
# vector to store 4 edge cases for the numeric arguments that need testing:
EDGE.CASES=list(NULL, NA, NaN, '')
#------------------------------------------------------------------------------
# start.date:
test_that("start.date that isn't a date fails with useful message", {
expect_error(colony_forecast(start.date='TextNotDate', nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST),
regexp='start.date must be YYYY-MM-DD')
})
test_that("start.date that isn't in correct format fails with useful message", {
expect_error(colony_forecast(start.date='190-01-01', nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST),
regexp='start.date must be YYYY-MM-DD')
})
#------------------------------------------------------------------------------
# nmonth:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in nmonth argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=EDGE.CASES[[i]],
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
#------------------------------------------------------------------------------
# nreps:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in nreps argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=EDGE.CASES[[i]],
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("nreps=0 fails with useful message", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=0,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST),
regexp='nreps must be positive')
})
test_that("Function works fine for nreps=1", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=1,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# I0 and A0:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in I0 argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=EDGE.CASES[[i]], A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in A0 argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=EDGE.CASES[[i]],
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("Function works fine if I0=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=0, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
test_that("Function works fine for A0=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=0,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
test_that("Function works fine for I0=0 and A0=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=0, A0=0,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# delta:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in delta argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=EDGE.CASES[[i]],
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("Error if delta is not of length 2, with useful message", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=0.02,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST),
regexp='delta must be a vector of length 2')
})
test_that("Function works if delta is of length 2 but is an unnamed vector", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=c(0.02, 0.01),
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# breeding.pairs.planned:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in breeding.pairs.planned argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=EDGE.CASES[[i]],
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("function works for breeding.pairs.planned=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=0,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# breeding.control:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in breeding.control argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=EDGE.CASES[[i]],
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("function works for breeding.control=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=0,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# breeding.pairs.planned vs. breeding.control:
# - run model for breeding.pairs.planned=0 (with random seed set to 123):
out1=colony_forecast(seed=123, start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=0,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST)
# - run model for breeding.control=0 (with random seed set to 123):
out2=colony_forecast(seed=123, start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=0,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST)
# test that out1=out2:
sapply(1:length(out1$Xdf), function(j) {
# print(NREPS.TEST-j)
test_that("Same results for infants when breeding.pairs.planned=0 as for breeding.control=0", {
expect_equal(object=out1$Xdf[[j]]$I, expected=out2$Xdf[[j]]$I)
})
test_that("Same results for adults when breeding.pairs.planned=0 as for breeding.control=0", {
expect_equal(object=out1$Xdf[[j]]$A, expected=out2$Xdf[[j]]$A)
})
})
#------------------------------------------------------------------------------
# lsz.dist:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in lsz.dist argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=EDGE.CASES[[i]],
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("Function works when lsz.dist is of length 1", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=1,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# transfer.rate:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in lsz.dist argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=EDGE.CASES[[i]],
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("Function works for transfer.rate=0", {
expect_no_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=0,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
test_that("Function failsfor transfer.rate<0", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=-0.1,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
#------------------------------------------------------------------------------
# run model for zero breeding, zero transfers and zero deaths
# - expect outputs for infants and adults to be constant, i.e. the same as initial values for each month
out3=colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=c(0,0),
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=0,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=0,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST)
# reference matrix of initial values of infants and adults, for comparison to model output:
I0.reference=matrix(rep(I0.TEST), nrow=5, ncol=25)
A0.reference=matrix(rep(A0.TEST), nrow=5, ncol=25)
test_that("Constant number of infants when delta, breeding.control and transfer.rate are all zero", {
# - test that all quantiles are equal to I0 value:
expect_equal(unname(out3$Iq), expected=I0.reference, ignore_attr = TRUE)
})
test_that("Constant number of adults when delta, breeding.control and transfer.rate are all zero", {
# - test that all quantiles are equal to A0 value:
expect_equal(unname(out3$Aq), expected=A0.reference, ignore_attr = TRUE)
})
#------------------------------------------------------------------------------
# issues:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in issues argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=EDGE.CASES[[i]],
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST))
})
})
test_that("Function throws error with useful message if length of issues is neither 1 nor nmonth", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=c(0,0,0,0),
relocations=RELOCATIONS.TEST,
quantiles=QUANTILES.TEST),
regexp='issues must have length 1 or nmonth')
})
#------------------------------------------------------------------------------
# relocations:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in relocations argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=EDGE.CASES[[i]],
quantiles=QUANTILES.TEST))
})
})
test_that("Function throws error with useful message if length of relocations is neither 1 nor nmonth", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=c(0,0,0,0),
quantiles=QUANTILES.TEST),
regexp='relocations must have length 1 or nmonth')
})
#------------------------------------------------------------------------------
# quantiles:
sapply(1:length(EDGE.CASES), function(i) {
test_that("Function throws error and stops for edge cases in quantiles argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=EDGE.CASES[[i]]))
})
})
test_that("Function throws error and stops for edge cases in quantiles argument", {
expect_error(colony_forecast(start.date=TEST.START, nmonth=NMONTH.TEST,
nreps=NREPS.TEST,
I0=I0.TEST, A0=A0.TEST,
delta=DELTA.TEST,
breeding.pairs.planned=BREEDING.PAIRS.TEST,
breeding.control=BREEDING.CONTROL.TEST,
lsz.dist=LITTER.SIZE.DIST.TEST,
transfer.rate=TRANSFER.RATE.TEST,
issues=ISSUES.TEST,
relocations=RELOCATIONS.TEST,
quantiles=c(110)))
})