Skip to content

Commit

Permalink
Merge pull request #172 from mrc-ide/feat/itn_usage
Browse files Browse the repository at this point in the history
Add ITN usage renderer
  • Loading branch information
giovannic authored Jul 27, 2022
2 parents ac5772a + 6da83ff commit 6683547
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/vector_control.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ spraying_decay <- function(t, theta, gamma) {
net_usage_renderer <- function(net_time, renderer) {
function(t) {
renderer$render(
'net_usage',
'n_use_net',
net_time$get_index_of(-1)$not(TRUE)$size(),
t
)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-vector-control.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,20 @@ test_that('prob_bitten correctly combines spraying and net probabilities', {
tolerance=1e-4
)
})

test_that('usage renderer outputs correct values', {
timestep <- 150

all <- individual::IntegerVariable$new(c(100, 50, 5, 50))
half <- individual::IntegerVariable$new(c(100, 50, -1, -1))
none <- individual::IntegerVariable$new(rep(-1, 4))

renderer <- list(render = mockery::mock())
net_usage_renderer(all, renderer)(timestep)
net_usage_renderer(half, renderer)(timestep)
net_usage_renderer(none, renderer)(timestep)

mockery::expect_args(renderer$render, 1, 'n_use_net', 4, timestep)
mockery::expect_args(renderer$render, 2, 'n_use_net', 2, timestep)
mockery::expect_args(renderer$render, 3, 'n_use_net', 0, timestep)
})

0 comments on commit 6683547

Please sign in to comment.