Skip to content

Commit

Permalink
Style the tests for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbaazam committed Nov 6, 2023
1 parent 6c0fcbc commit 307941c
Showing 1 changed file with 78 additions and 27 deletions.
105 changes: 78 additions & 27 deletions tests/testthat/tests-sim.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ test_that("Chains can be simulated", {
)
)
# Other checks
expect_length(
chain_sim(
n = 2,
offspring = "pois",
lambda = 0.5
),
2
)
expect_length(
chain_sim(
n = 10,
offspring = "pois",
stat = "length",
lambda = 0.9
),
10
)
expect_s3_class(
chain_sim(
n = 10,
Expand All @@ -29,47 +46,81 @@ test_that("Chains can be simulated", {
),
"data.frame"
)
expect_false(any(is.finite(chain_sim(
n = 2, "pois", "length", lambda = 0.5,
infinite = 1
))))
expect_no_error(chain_sim(
n = 2, offspring = "pois", "size", lambda = 0.9,
tree = TRUE
))

tf <- 3
set.seed(12)
expect_true(
all(chain_sim(
n = 2, offspring = "pois", "size", lambda = 0.9,
tree = TRUE, serial = function(n) {
rlnorm(n, meanlog = 0.58, sdlog = 1.58)
}, tf = tf
)$time < tf)
expect_false(
any(
is.finite(
chain_sim(
n = 2,
offspring = "pois",
stat = "length",
lambda = 0.5,
infinite = 1
)
)
)
)
expect_no_error(
chain_sim(
n = 2,
offspring = "pois",
stat = "size",
lambda = 0.9,
tree = TRUE
)
)
})

test_that("Errors are thrown", {
expect_error(chain_sim(n = 2, "dummy"), "does not exist")
expect_error(chain_sim(n = 2, "lnorm", meanlog = log(1.6)), "integer")
expect_error(
chain_sim(n = 2, offspring = pois, "length", lambda = 0.9),
chain_sim(
n = 2,
"dummy"
),
"does not exist"
)
expect_error(
chain_sim(
n = 2,
offspring = "lnorm",
meanlog = log(1.6)
),
"integer"
)
expect_error(
chain_sim(
n = 2,
offspring = pois,
stat = "length",
lambda = 0.9
),
"not found"
)
expect_error(chain_sim(
n = 2, offspring = "pois", "size", lambda = 0.9,
serial = c(1, 2), "must be a function"
))
expect_error(
chain_sim(n = 2, offspring = c(1, 2), "length", lambda = 0.9),
chain_sim(
n = 2,
offspring = "pois",
stat = "size",
lambda = 0.9,
serial = c(1, 2)
),
"must be a function"
)
expect_error(
chain_sim(
n = 2,
offspring = c(1, 2),
stat = "length",
lambda = 0.9
),
"not a character string"
)
expect_error(
chain_sim(n = 2, offspring = list(1, 2), "length", lambda = 0.9),
chain_sim(
n = 2,
offspring = list(1, 2),
stat = "length",
lambda = 0.9
),
"not a character string"
)
expect_error(
Expand Down

0 comments on commit 307941c

Please sign in to comment.