Skip to content

Commit

Permalink
Merge branch 'dev' into new_epi_outputs_function
Browse files Browse the repository at this point in the history
  • Loading branch information
RJSheppard authored May 24, 2024
2 parents 8f11a06 + ab030d7 commit 09a8c3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ calculate_initial_ages <- function(parameters) {
n_pop <- get_human_population(parameters, 0)
# check if we've set up a custom demography
if (!parameters$custom_demography) {
return(round(rexp(
return(round(rtexp(
n_pop,
rate = 1 / parameters$average_age
1 / parameters$average_age,
max(EQUILIBRIUM_AGES)*365
)))
}

Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-demography.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
test_that('calculate_initial_ages defaults to an exponential distribution', {
test_that('calculate_initial_ages defaults to a truncated exponential distribution', {
parameters <- get_parameters(list(human_population = 4))
mock_exp <- mockery::mock(seq(4))
mockery::stub(calculate_initial_ages, 'rexp', mock_exp)
mockery::stub(calculate_initial_ages, 'rtexp', mock_exp)
ages <- calculate_initial_ages(parameters)
mockery::expect_args(
mock_exp,
1,
parameters$human_population,
1 / parameters$average_age
1 / parameters$average_age,
max(EQUILIBRIUM_AGES)*365
)
})

Expand Down Expand Up @@ -70,4 +71,4 @@ test_that('match_timestep works on the boundaries', {
expect_equal(match_timestep(c(0, 50, 100), 99), 2)
expect_equal(match_timestep(c(0, 50, 100), 100), 3)
expect_equal(match_timestep(c(0, 50, 100), 101), 3)
})
})

0 comments on commit 09a8c3e

Please sign in to comment.