Skip to content

Commit 9b2e0d6

Browse files
committedJan 27, 2022
1 parent 4ba4226 commit 9b2e0d6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
 

‎tests/testthat/test-ce.R

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Test ce() function
2+
test_that("ce errors when calf survival out of bounds", {
3+
# example species: bottlenose dolphin
4+
S0.w = 0.865
5+
S1plus.w = 0.951
6+
nages.w = 10
7+
AgeMat.w = 6
8+
# Get number of individuals per recruit in terms of mature individuals (N0.w)
9+
NPROut <- npr(S0 = S0.w, S1plus = S1plus.w, nages = nages.w, AgeMat = AgeMat.w, E = 0)
10+
11+
N0 <- NPROut$npr # mature numbers per recruit
12+
# Get number of individuals per recruit in terms of individuals aged 1+ (P0.w)
13+
P0 <- NPROut$P1r # 1+ nums per recruit
14+
15+
expect_error(ce(
16+
S0 = 1.1, S1plus = S1plus.w,
17+
nages = nages.w,
18+
AgeMat = AgeMat.w,
19+
E = 0.01, z = 2.39, A = 2, N0 = N0, P0 = P0
20+
))
21+
})
22+
23+
test_that("ce (normalized sustainable yield) is higher when S1+ is higher",
24+
{
25+
# example species: bottlenose dolphin
26+
S0.w = 0.865
27+
S1plus.w = 0.951
28+
nages.w = 10
29+
AgeMat.w = 6
30+
31+
NPROut <- npr(S0 = S0.w, S1plus = S1plus.w, nages = nages.w, AgeMat = AgeMat.w, E = 0)
32+
33+
N0 <- NPROut$npr # mature numbers per recruit
34+
P0 <- NPROut$P1r # 1+ nums per recruit
35+
36+
x <- ce(
37+
S0 = S0.w, S1plus = 0.81,
38+
nages = nages.w,
39+
AgeMat = AgeMat.w,
40+
E = 0.01, z = 2.39, A = 2, N0 = N0, P0 = P0
41+
)
42+
43+
y <- ce(
44+
S0 = S0.w, S1plus = 0.99,
45+
nages = nages.w,
46+
AgeMat = AgeMat.w,
47+
E = 0.01, z = 2.39, A = 2, N0 = N0, P0 = P0
48+
)
49+
50+
expect_true(y>x)
51+
})

0 commit comments

Comments
 (0)
Please sign in to comment.