tests/testthat/helper-test-vaccination-distribution.R

library(nimue)
library(individual)

# helper functions
divmod <- function(a,b){
  a <- as.integer(a)
  b <- as.integer(b)
  c(
    quo = a %/% b,
    rem = a %% b
  )
}

# n: number of "things"
# p: set of "places" they can go
distribute <- function(n,p){
  n <- as.integer(n)
  p <- as.integer(p)
  distn <- rep(0L,p)
  div <- divmod(n,p)
  for(i in 0:(p-1)){
    distn[i+1] <- div[["quo"]] + (i < div[["rem"]])
  }
  return(distn)
}
mrc-ide/safir documentation built on Aug. 2, 2022, 10:47 a.m.