diff --git a/R/sim_all.R b/R/sim_all.R index b0417e69b1af94a8617ce5fa39828a388f66abfb..9d6b6b7fb43311f94dca6003b6427c22fb8c9fe4 100644 --- a/R/sim_all.R +++ b/R/sim_all.R @@ -28,7 +28,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ ################################################# - ########## Input Validation Tests ############### + ########## Input Validation Test ############### ################################################# ########### validate the utility function ######## @@ -41,17 +41,17 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ if (missing(bcoeff)) { stop("Argument 'bcoeff' is required.") } - + # Check if bcoeff is a list if (!is.list(bcoeff)) { stop("Argument 'bcoeff' must be a list.") } - + # Check if values in bcoeff are numeric if (!all(sapply(bcoeff, is.numeric))) { stop("Values in 'bcoeff' must be numeric.") } - + #### check that all the coefficients in utility function have a cooresponding value in bcoeff #### # Extract coefficients from utility function starting with "b" coeff_names_ul <- unique(unlist(lapply(u, function(u) { @@ -64,7 +64,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ }))) return(coef_names) }))) - + # Check if all utility function coefficients starting with "b" are covered in bcoeff list missing_coeffs <- coeff_names_ul[!(coeff_names_ul %in% names(bcoeff))] if (length(missing_coeffs) > 0) { @@ -78,11 +78,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ if (!dir.exists(designpath)) { stop(" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified") } - + ################################################# ########## End Validation Tests ################# ################################################# - + designfile<-list.files(designpath,full.names = T) designname <- stringr::str_remove_all(list.files(designpath,full.names = F), "(.ngd|_|.RDS)") ## Make sure designnames to not contain file ending and "_", as the may cause issues when replace diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index 63af0c06f0b595c355ed0e6ef922eee3e640309f..8809a1169cd18196e4da209f19e222171cef5a32 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-sim_all.R b/tests/testthat/test-sim_all.R index 962ecbe593a2489fb204e53217f7d415f9a26931..e4e4a9d359c9a1b1bd5aa99da72967bf0da5b383 100644 --- a/tests/testthat/test-sim_all.R +++ b/tests/testthat/test-sim_all.R @@ -124,10 +124,10 @@ test_that("Utility functions are valid", { test_that("Design path must be a valid directory", { # Test case: designpath is not a character string expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = 123, u = ul, bcoeff = bcoeff)) - + # Test case: designpath does not exist expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = '/nonexistent/path', u = ul, bcoeff = bcoeff)) - + # Test case: designpath is not a directory expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = 'path/to/a/file.txt', u = ul, bcoeff = bcoeff)) }) @@ -135,13 +135,13 @@ test_that("Design path must be a valid directory", { test_that("Resps must be an integer", { # Test case: resps is missing expect_error(sim_all(nosim = nosim, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)) - + # Test case: resps is not an integer expect_error(sim_all(nosim = nosim, resps = "abc", destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)) - + # Test case: resps is a numeric but not an integer expect_error(sim_all(nosim = nosim, resps = 1.5, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)) - + }) test_that("Function exists in simulateDCE", { @@ -149,10 +149,10 @@ test_that("Function exists in simulateDCE", { }) test_that("Simulation results are reasonable", { - + result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff) - + expect_gt(result1$est_bsq, -1) expect_lt(result1$est_bsq, 1) - + })