forked from BiologicalRecordsCentre/sparta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-errorChecks.R
272 lines (235 loc) · 8.04 KB
/
test-errorChecks.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
# Test error for startDate not in date format
test_that("Does it detect when startDate is not in a date format?", {
expect_error(
errorChecks(startDate = df$time_period),
'startDate is not in a date format. This should be of class "Date" or "POSIXct"'
)
})
# Test error for startDate containing NAs
test_that("Does it detect when startDate contains NAs?", {
expect_error(
errorChecks(startDate = df$time_period_missing),
"startDate must not contain NAs"
)
})
# Test error for Date not being a data.frame or date vector
test_that("Does it detect when date is not a dataframe or date vector?", {
expect_error(
errorChecks(Date = df$time_period),
"Date must be a data.frame or date vector"
)
})
# Test error for Date containing NAs
test_that("Does it detect when time_period_missing contains NAs?", {
expect_error(
errorChecks(Date = df$time_period_missing),
"Date must not contain NAs"
)
})
# Test error for endDate not in date format
test_that("Does it detect when time_period is not in a date format?", {
expect_error(
errorChecks(endDate = df$time_period),
'endDate is not in a date format. This should be of class "Date" or "POSIXct"'
)
})
# Test error for endDate containing NAs
test_that("Does it detect when endDate contains NAs?", {
expect_error(
errorChecks(endDate = df$time_period_missing),
"endDate must not contain NAs"
)
})
# Test error for dist_sub must be integer or numeric
test_that("Does it detect when dist_sub is not an integer or numeric value?", {
expect_error(
errorChecks(dist_sub = df$dist_sub_chr, sim_sub = df$sim_sub),
"dist_sub must be integer or numeric"
)
expect_error(
errorChecks(dist_sub = df$dist_sub_fac, sim_sub = df$sim_sub),
"dist_sub must be integer or numeric"
)
})
test_that("Does it detect when sim_sub is not an integer or numeric value?", {
expect_error(
errorChecks(dist_sub = df$dist_sub, sim_sub = df$sim_sub_fac),
"sim_sub must be integer or numeric"
)
expect_error(
errorChecks(dist_sub = df$dist_sub, sim_sub = df$sim_sub_chr),
"sim_sub must be integer or numeric"
)
})
# Test error for useIterations must be logical
test_that("Does it detect when iterations are not logical?", {
useIterations_num <- 1
useIterations_chr <- "TRUE"
expect_error(
errorChecks(useIterations = useIterations_chr),
"useIterations must be logical"
)
expect_error(
errorChecks(useIterations = useIterations_num),
"useIterations must be logical"
)
})
# Test error for iterations, family, thinning, and numeric parameters
test_that("Does it detect when iterations are not an integer?", {
expect_error(
errorChecks(iterations = "1000"),
"iterations must be numeric or integer"
)
})
test_that("Does it detect when Family is not Binomial or Bernoulli?", {
expect_error(
errorChecks(family = "Poisson"),
"family must be either Binomial or Bernoulli"
)
})
test_that("Does it detect when thinning is larger than the number of iterations?", {
expect_error(
errorChecks(n_iterations = 1000, burnin = 500, thinning = 1100, n_chains = 3),
"thinning must not be larger that the number of iteration (n_iterations)",
fixed = TRUE
)
})
test_that("Does it detect when n_iterations is not an integer", {
expect_error(
errorChecks(n_iterations = "1000", burnin = 500, thinning = 5, n_chains = 3),
"n_iterations should be numeric"
)
})
test_that("Does it detect when burnin is not an integer?", {
expect_error(
errorChecks(n_iterations = 1000, burnin = "500", thinning = 5, n_chains = 3),
"burnin should be numeric"
)
})
test_that("Does it detect when thinning is not an integer?", {
expect_error(
errorChecks(n_iterations = 1000, burnin = 500, thinning = "5", n_chains = 3),
"thinning should be numeric"
)
})
test_that("Does it detect when n_chains is not an integer?", {
expect_error(
errorChecks(n_iterations = 1000, burnin = 500, thinning = 5, n_chains = "3"),
"n_chains should be numeric"
)
})
test_that("Does it detect when The seed is not an integer?", {
expect_error(
errorChecks(seed = "1"),
"seed muct be numeric"
)
})
# Test for detecting missing year_col when start_col and end_col are NA
test_that("can it detect when year_col is missing with start_col and end_col as NA?", {
expect_error(
errorChecks(year_col = NA, start_col = NA, end_col = df$time_period[1]),
"year_col or start_col and end_col must be given"
)
})
# Test for detecting missing end_col when year_col is NA
test_that("can it detect when end_col is missing with year_col as NA?", {
expect_error(
errorChecks(year_col = NA, start_col = df$time_period[1], end_col = NA),
"year_col or start_col and end_col must be given"
)
})
# Test for detecting simultaneous use of year_col with start_col and end_col
test_that("can it detect the simultaneous use of year_col with start_col and end_col?", {
expect_error(
errorChecks(year_col = NA, start_col = df$time_period[1], end_col = df$time_period[1]),
"year_col cannot be used at the same time as start_col and end_col"
)
})
# Test for detecting phi value below the permitted range
test_that("can it detect when phi is below the permitted range?", {
expect_error(
errorChecks(phi = 0.1),
"phi is outside permitted range of 0.50 to 0.95"
)
})
# Test for detecting phi value above the permitted range
test_that("can it detect when phi is above the permitted range?", {
expect_error(
errorChecks(phi = 0.99),
"phi is outside permitted range of 0.50 to 0.95"
)
})
# Test for detecting alpha value below the permitted range
test_that("can it detect when alpha is below the permitted range?", {
expect_error(
errorChecks(alpha = 0.05),
"alpha is outside permitted range of 0.08 to 0.50"
)
})
# Test for detecting alpha value above the permitted range
test_that("can it detect when alpha is above the permitted range?", {
expect_error(
errorChecks(alpha = 0.99),
"alpha is outside permitted range of 0.08 to 0.50"
)
})
# Test for detecting fres_site_filter not being a character vector
test_that("can it detect when fres_site_filter is not a character vector?", {
expect_error(
errorChecks(fres_site_filter = c(1, 5, 10, 12)),
"fres_site_filter must be a character vector"
)
})
# Test for detecting non_benchmark_sp not being a character vector
test_that("can it detect when non_benchmark_sp is not a character vector?", {
expect_error(
errorChecks(non_benchmark_sp = c(1, 5, 10, 12)),
"non_benchmark_sp must be a character vector"
)
})
# Test for detecting fres_site_filter not being a character vector
test_that("can it detect when fres_site_filter is not a character vector and is a single number?", {
expect_error(
errorChecks(fres_site_filter = 1),
"fres_site_filter must be a character vector"
)
})
# Test for detecting fres_site_filter not being a character vector
test_that("can it detect when fres_site_filter is not a character vector and is a single number?", {
expect_error(
errorChecks(non_benchmark_sp = 1),
"non_benchmark_sp must be a character vector"
)
})
# Test for detecting incorrect time_periods format
test_that("can it detect when time_periods format is incorrect?", {
expect_error(
errorChecks(time_periods = as.matrix(df$time_period)),
'time_periods should be a data.frame. e.g. "data.frame(start=c(1980,1990),end=c(1989,1999))"',
fixed = TRUE
)
})
# Test for detecting incorrect filepath for a .exe file
test_that("can it detect when the filepath is not to a '.exe' file?", {
temp <- tempfile()
dir.create(temp)
expect_error(
errorChecks(frespath = temp),
"filepath is not the path to a '.exe' file"
)
})
# Test for detecting non-existent .exe file
test_that("can it detect when a .exe file does not exist?", {
expect_error(
errorChecks(frespath = "file.exe"),
"file.exe does not exist"
)
})
# Test error for site must not contain empty values
test_that("Does it detect empty string values?", {
expect_error(
errorChecks(site = c("a", "b", "")),
"site must not contain empty values (i.e. '')",
fixed = TRUE
)
})