Skip to content

Commit 5ec150a

Browse files
committed
add tests for add_trans() and make_ptable #58
openjournals/joss-reviews#3888
1 parent 23a58f0 commit 5ec150a

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

tests/testthat/test-add_trans.R

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# test add trans
2+
test_that("add_trans() returns valid color code",
3+
{
4+
xx <- add_trans("red", 100)
5+
expect_true(grepl(pattern = "^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{3})$",x = xx))
6+
})

tests/testthat/test-make_ptable.R

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Test the make_ptable function
2+
3+
test_that("make_ptable produces a dataframe", {
4+
parms <- list(
5+
S0 = 0.944, S1plus = 0.99, K1plus = 9000, AgeMat = 18, nages = 20,
6+
z = 2.39, lambdaMax = 1.02
7+
)
8+
initdepl.vec <- c(0.2, 0.5, 0.9)
9+
nyears <- 100
10+
high.list.const <- lapply(
11+
X = initdepl.vec,
12+
function(x) {
13+
projections(
14+
NOut = 50,
15+
ConstantBycatch = list(Catch = 25, CV = 0.3),
16+
InitDepl = x,
17+
lh.params = parms,
18+
nyears = nyears,
19+
obs_CV = 0.1
20+
)
21+
}
22+
)
23+
med.list.const <- lapply(
24+
X = initdepl.vec,
25+
function(x) {
26+
projections(
27+
NOut = 50,
28+
ConstantBycatch = list(Catch = 12, CV = 0.3),
29+
InitDepl = x,
30+
lh.params = parms,
31+
nyears = nyears,
32+
obs_CV = 0.1
33+
)
34+
}
35+
)
36+
low.list.const <- lapply(
37+
X = initdepl.vec,
38+
function(x) {
39+
projections(
40+
NOut = 50,
41+
ConstantBycatch = list(Catch = 2, CV = 0.3),
42+
InitDepl = x,
43+
lh.params = parms,
44+
nyears = nyears,
45+
obs_CV = 0.1
46+
)
47+
}
48+
)
49+
zero.list.const <- lapply(
50+
X = initdepl.vec,
51+
function(x) {
52+
projections(
53+
NOut = 50,
54+
ConstantBycatch = list(Catch = 0, CV = 0),
55+
InitDepl = x,
56+
lh.params = parms,
57+
nyears = nyears,
58+
obs_CV = 0.1
59+
)
60+
}
61+
)
62+
traj.list <- list(
63+
high.list.const,
64+
med.list.const,
65+
low.list.const,
66+
zero.list.const
67+
)
68+
xx <- make_ptable(traj.list = traj.list, depletion = initdepl.vec, mnpl = 0.5)
69+
expect_s3_class(xx, "tbl_df")
70+
})
71+
72+
test_that("Probabilities and relative abundances to not go above 1", {
73+
parms <- list(
74+
S0 = 0.944, S1plus = 0.99, K1plus = 9000, AgeMat = 18, nages = 20,
75+
z = 2.39, lambdaMax = 1.02
76+
)
77+
initdepl.vec <- c(0.2, 0.5, 0.9)
78+
nyears <- 100
79+
high.list.const <- lapply(
80+
X = initdepl.vec,
81+
function(x) {
82+
projections(
83+
NOut = 50,
84+
ConstantBycatch = list(Catch = 25, CV = 0.3),
85+
InitDepl = x,
86+
lh.params = parms,
87+
nyears = nyears,
88+
obs_CV = 0.1
89+
)
90+
}
91+
)
92+
med.list.const <- lapply(
93+
X = initdepl.vec,
94+
function(x) {
95+
projections(
96+
NOut = 50,
97+
ConstantBycatch = list(Catch = 12, CV = 0.3),
98+
InitDepl = x,
99+
lh.params = parms,
100+
nyears = nyears,
101+
obs_CV = 0.1
102+
)
103+
}
104+
)
105+
low.list.const <- lapply(
106+
X = initdepl.vec,
107+
function(x) {
108+
projections(
109+
NOut = 50,
110+
ConstantBycatch = list(Catch = 2, CV = 0.3),
111+
InitDepl = x,
112+
lh.params = parms,
113+
nyears = nyears,
114+
obs_CV = 0.1
115+
)
116+
}
117+
)
118+
zero.list.const <- lapply(
119+
X = initdepl.vec,
120+
function(x) {
121+
projections(
122+
NOut = 50,
123+
ConstantBycatch = list(Catch = 0, CV = 0),
124+
InitDepl = x,
125+
lh.params = parms,
126+
nyears = nyears,
127+
obs_CV = 0.1
128+
)
129+
}
130+
)
131+
traj.list <- list(
132+
high.list.const,
133+
med.list.const,
134+
low.list.const,
135+
zero.list.const
136+
)
137+
xx <- make_ptable(traj.list = traj.list, depletion = initdepl.vec, mnpl = 0.5)
138+
139+
expect_false(any(xx[, c("prebuild50", "prebuild100", "abundrel10", "abundrel20", "abundrel50")] > 1))
140+
})

0 commit comments

Comments
 (0)