Skip to content

Commit 980d1fe

Browse files
committed
Added pSizeAtGen tests
1 parent d3fa6b3 commit 980d1fe

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/testthat/test-pSizeAtGen.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
test_that("pSizeAtGen() matches brute-force calculation", {
2+
pfs1 <- pSizeAtGen(g=1, n=1, j=4, R=1.2, k=0.33)
3+
pfs2 <- pSizeAtGen(g=2, n=1, j=4, R=1.2, k=0.33)
4+
pfs3 <- pSizeAtGen(g=3, n=1, j=4, R=1.2, k=0.33)
5+
6+
d <- dnbinom(0:3, mu=1.2, size=0.33)
7+
dnb1 <- d[4]
8+
dnb2 <- d[3] * d[2] * d[1] * 2 + d[2] * d[3]
9+
dnb3 <- d[2]^3
10+
11+
expect_equal(pfs1, dnb1, tolerance = sqrt(.Machine$double.eps))
12+
expect_equal(pfs2, dnb2, tolerance = sqrt(.Machine$double.eps))
13+
expect_equal(pfs3, dnb3, tolerance = sqrt(.Machine$double.eps))
14+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test_that("pSizeAtGenSwitch1() matches brute-force calculation", {
2+
pfs1 <- pSizeAtGenSwitch1(g=1, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
3+
pfs2 <- pSizeAtGenSwitch1(g=2, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
4+
pfs3 <- pSizeAtGenSwitch1(g=3, n=1, j=4, R0=1.2, k0=0.33, Rc=0.9, kc=0.8)
5+
6+
d0 <- dnbinom(0:3, mu=1.2, size=0.33)
7+
dc <- dnbinom(0:2, mu=0.9, size=0.8)
8+
dnb1 <- d0[4]
9+
dnb2 <- d0[3] * dc[2] * dc[1] * 2 + d0[2] * dc[3]
10+
dnb3 <- d0[2] * dc[2]^2
11+
12+
expect_equal(pfs1, dnb1, tolerance = sqrt(.Machine$double.eps))
13+
expect_equal(pfs2, dnb2, tolerance = sqrt(.Machine$double.eps))
14+
expect_equal(pfs3, dnb3, tolerance = sqrt(.Machine$double.eps))
15+
})

0 commit comments

Comments
 (0)