From b8ac7fb6ee2fbd69d26a3e0110773849873b3dff Mon Sep 17 00:00:00 2001
From: Peter Winskill
Date: Fri, 2 Jun 2023 07:55:07 +0100
Subject: [PATCH] Check drug inputs are a list
---
R/drug_parameters.R | 1 +
tests/testthat/test-treatment.R | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/R/drug_parameters.R b/R/drug_parameters.R
index f5e62a27..4f205604 100644
--- a/R/drug_parameters.R
+++ b/R/drug_parameters.R
@@ -24,6 +24,7 @@ SP_AQ_params <- c(0.9, 0.32, 4.3, 38.1)
#' @param drugs a list of drug parameters, can be set using presets
#' @export
set_drugs <- function(parameters, drugs) {
+ stopifnot(is.list(drugs))
keys <- c(
'drug_efficacy',
'drug_rel_c',
diff --git a/tests/testthat/test-treatment.R b/tests/testthat/test-treatment.R
index d52fc007..9e40c0da 100644
--- a/tests/testthat/test-treatment.R
+++ b/tests/testthat/test-treatment.R
@@ -78,3 +78,12 @@ test_that('You cannot set invalid coverages', {
)
)
})
+
+test_that('set_drugs errors if a list is not provided', {
+ parameters <- get_parameters()
+ expect_error(
+ set_drugs(parameters, AL_params),
+ "is.list(drugs) is not TRUE",
+ fixed = TRUE
+ )
+})