11test_that(" check_inputs passes with valid MAP inputs" , {
22 # Create mock objects
33 model <- function () {}
4+ attr(model , " parameters" ) <- c(" CL" , " V" )
45 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
56 parameters <- list (CL = 1 , V = 10 )
67 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -13,6 +14,7 @@ test_that("check_inputs passes with valid MAP inputs", {
1314test_that(" check_inputs passes with valid PLS inputs" , {
1415 # Create mock objects
1516 model <- function () {}
17+ attr(model , " parameters" ) <- c(" CL" , " V" )
1618 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
1719 parameters <- list (CL = 1 , V = 10 )
1820 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -25,6 +27,7 @@ test_that("check_inputs passes with valid PLS inputs", {
2527test_that(" check_inputs passes with valid pls inputs (lowercase)" , {
2628 # Create mock objects
2729 model <- function () {}
30+ attr(model , " parameters" ) <- c(" CL" , " V" )
2831 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
2932 parameters <- list (CL = 1 , V = 10 )
3033 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -37,6 +40,7 @@ test_that("check_inputs passes with valid pls inputs (lowercase)", {
3740test_that(" check_inputs passes with valid MAP inputs (lowercase)" , {
3841 # Create mock objects
3942 model <- function () {}
43+ attr(model , " parameters" ) <- c(" CL" , " V" )
4044 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
4145 parameters <- list (CL = 1 , V = 10 )
4246 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -49,6 +53,7 @@ test_that("check_inputs passes with valid MAP inputs (lowercase)", {
4953test_that(" check_inputs passes with valid censoring argument" , {
5054 # Create mock objects
5155 model <- function () {}
56+ attr(model , " parameters" ) <- c(" CL" , " V" )
5257 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
5358 parameters <- list (CL = 1 , V = 10 )
5459 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -61,6 +66,7 @@ test_that("check_inputs passes with valid censoring argument", {
6166test_that(" check_inputs passes with other type values" , {
6267 # Create mock objects
6368 model <- function () {}
69+ attr(model , " parameters" ) <- c(" CL" , " V" )
6470 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
6571 parameters <- list (CL = 1 , V = 10 )
6672 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -84,6 +90,7 @@ test_that("check_inputs fails when model is NULL for MAP type", {
8490
8591test_that(" check_inputs fails when data is NULL for MAP type" , {
8692 model <- function () {}
93+ attr(model , " parameters" ) <- c(" CL" , " V" )
8794 parameters <- list (CL = 1 , V = 10 )
8895 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
8996 regimen <- list (dose = 100 , interval = 12 )
@@ -96,6 +103,7 @@ test_that("check_inputs fails when data is NULL for MAP type", {
96103
97104test_that(" check_inputs fails when parameters is NULL for MAP type" , {
98105 model <- function () {}
106+ attr(model , " parameters" ) <- c(" CL" , " V" )
99107 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
100108 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
101109 regimen <- list (dose = 100 , interval = 12 )
@@ -108,6 +116,7 @@ test_that("check_inputs fails when parameters is NULL for MAP type", {
108116
109117test_that(" check_inputs fails when omega is NULL for MAP type" , {
110118 model <- function () {}
119+ attr(model , " parameters" ) <- c(" CL" , " V" )
111120 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
112121 parameters <- list (CL = 1 , V = 10 )
113122 regimen <- list (dose = 100 , interval = 12 )
@@ -120,6 +129,7 @@ test_that("check_inputs fails when omega is NULL for MAP type", {
120129
121130test_that(" check_inputs fails when regimen is NULL for MAP type" , {
122131 model <- function () {}
132+ attr(model , " parameters" ) <- c(" CL" , " V" )
123133 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
124134 parameters <- list (CL = 1 , V = 10 )
125135 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -132,6 +142,7 @@ test_that("check_inputs fails when regimen is NULL for MAP type", {
132142
133143test_that(" check_inputs fails when model is not a function" , {
134144 model <- " not_a_function"
145+ attr(model , " parameters" ) <- c(" CL" , " V" )
135146 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
136147 parameters <- list (CL = 1 , V = 10 )
137148 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -145,6 +156,7 @@ test_that("check_inputs fails when model is not a function", {
145156
146157test_that(" check_inputs fails when model is a list (not a function)" , {
147158 model <- list (not_a_function = TRUE )
159+ attr(model , " parameters" ) <- c(" CL" , " V" )
148160 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
149161 parameters <- list (CL = 1 , V = 10 )
150162 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -158,6 +170,7 @@ test_that("check_inputs fails when model is a list (not a function)", {
158170
159171test_that(" check_inputs fails when censoring is not NULL and not character" , {
160172 model <- function () {}
173+ attr(model , " parameters" ) <- c(" CL" , " V" )
161174 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
162175 parameters <- list (CL = 1 , V = 10 )
163176 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -184,6 +197,7 @@ test_that("check_inputs fails when censoring is not NULL and not character", {
184197
185198test_that(" check_inputs allows NULL censoring" , {
186199 model <- function () {}
200+ attr(model , " parameters" ) <- c(" CL" , " V" )
187201 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
188202 parameters <- list (CL = 1 , V = 10 )
189203 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -195,6 +209,7 @@ test_that("check_inputs allows NULL censoring", {
195209
196210test_that(" check_inputs allows character censoring" , {
197211 model <- function () {}
212+ attr(model , " parameters" ) <- c(" CL" , " V" )
198213 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
199214 parameters <- list (CL = 1 , V = 10 )
200215 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -207,6 +222,7 @@ test_that("check_inputs allows character censoring", {
207222test_that(" check_inputs works with different function types" , {
208223 # Test with anonymous function
209224 model <- function (x ) x + 1
225+ attr(model , " parameters" ) <- c(" CL" , " V" )
210226 data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
211227 parameters <- list (CL = 1 , V = 10 )
212228 omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
@@ -216,5 +232,39 @@ test_that("check_inputs works with different function types", {
216232
217233 # Test with named function
218234 test_model <- function () {}
235+ attr(test_model , " parameters" ) <- c(" CL" , " V" )
219236 expect_no_error(check_inputs(test_model , data , parameters , omega , regimen , NULL , " MAP" ))
220- })
237+ })
238+
239+ test_that(" check_inputs fails when not all parameters are passed, and warning when too many are passed" , {
240+ model <- function () {}
241+ attr(model , " parameters" ) <- c(" CL" , " V" )
242+ data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
243+ parameters <- list (CL = 1 ) # , V = 10)
244+ omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
245+ regimen <- list (dose = 100 , interval = 12 )
246+
247+ # Should not throw any errors with NULL censoring
248+ expect_error(
249+ check_inputs(model , data , parameters , omega , regimen , NULL , " MAP" ),
250+ " One or more required parameters for the model have not been specified. Missing: V"
251+ )
252+
253+ parameters <- list (CL = 1 , V = 10 , V2 = 15 , Q = 23 )
254+ expect_warning(
255+ check_inputs(model , data , parameters , omega , regimen , NULL , " MAP" ),
256+ " Some supplied `parameters` are not supported by the model and will be ignored: V2, Q."
257+ )
258+ })
259+
260+ test_that(" check_inputs warns when no parameters are defined as model attribute" , {
261+ model <- function () {}
262+ data <- data.frame (time = 1 : 3 , dv = c(1 , 2 , 3 ))
263+ parameters <- list (CL = 1 ) # , V = 10)
264+ omega <- matrix (c(0.1 , 0 , 0 , 0.1 ), nrow = 2 )
265+ regimen <- list (dose = 100 , interval = 12 )
266+ expect_warning(
267+ check_inputs(model , data , parameters , omega , regimen , NULL , " MAP" ),
268+ " Parameter information for model missing"
269+ )
270+ })
0 commit comments