Skip to content
Snippets Groups Projects
Commit 0c1de67f authored by samuelsmock's avatar samuelsmock
Browse files

divergence fix

parent 6be6c256
Branches
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
################################################# #################################################
########## Input Validation Tests ############### ########## Input Validation Test ###############
################################################# #################################################
########### validate the utility function ######## ########### validate the utility function ########
...@@ -41,17 +41,17 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ ...@@ -41,17 +41,17 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
if (missing(bcoeff)) { if (missing(bcoeff)) {
stop("Argument 'bcoeff' is required.") stop("Argument 'bcoeff' is required.")
} }
# Check if bcoeff is a list # Check if bcoeff is a list
if (!is.list(bcoeff)) { if (!is.list(bcoeff)) {
stop("Argument 'bcoeff' must be a list.") stop("Argument 'bcoeff' must be a list.")
} }
# Check if values in bcoeff are numeric # Check if values in bcoeff are numeric
if (!all(sapply(bcoeff, is.numeric))) { if (!all(sapply(bcoeff, is.numeric))) {
stop("Values in 'bcoeff' must be numeric.") stop("Values in 'bcoeff' must be numeric.")
} }
#### check that all the coefficients in utility function have a cooresponding value in bcoeff #### #### check that all the coefficients in utility function have a cooresponding value in bcoeff ####
# Extract coefficients from utility function starting with "b" # Extract coefficients from utility function starting with "b"
coeff_names_ul <- unique(unlist(lapply(u, function(u) { coeff_names_ul <- unique(unlist(lapply(u, function(u) {
...@@ -64,7 +64,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ ...@@ -64,7 +64,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
}))) })))
return(coef_names) return(coef_names)
}))) })))
# Check if all utility function coefficients starting with "b" are covered in bcoeff list # 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))] missing_coeffs <- coeff_names_ul[!(coeff_names_ul %in% names(bcoeff))]
if (length(missing_coeffs) > 0) { if (length(missing_coeffs) > 0) {
...@@ -78,11 +78,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){ ...@@ -78,11 +78,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
if (!dir.exists(designpath)) { if (!dir.exists(designpath)) {
stop(" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified") stop(" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified")
} }
################################################# #################################################
########## End Validation Tests ################# ########## End Validation Tests #################
################################################# #################################################
designfile<-list.files(designpath,full.names = T) designfile<-list.files(designpath,full.names = T)
designname <- stringr::str_remove_all(list.files(designpath,full.names = F), 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 "(.ngd|_|.RDS)") ## Make sure designnames to not contain file ending and "_", as the may cause issues when replace
......
No preview for this file type
...@@ -124,10 +124,10 @@ test_that("Utility functions are valid", { ...@@ -124,10 +124,10 @@ test_that("Utility functions are valid", {
test_that("Design path must be a valid directory", { test_that("Design path must be a valid directory", {
# Test case: designpath is not a character string # Test case: designpath is not a character string
expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = 123, u = ul, bcoeff = bcoeff)) expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = 123, u = ul, bcoeff = bcoeff))
# Test case: designpath does not exist # Test case: designpath does not exist
expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = '/nonexistent/path', u = ul, bcoeff = bcoeff)) expect_error(sim_all(nosim = nosim, resps = resps, destype = destype, designpath = '/nonexistent/path', u = ul, bcoeff = bcoeff))
# Test case: designpath is not a directory # 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)) 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", { ...@@ -135,13 +135,13 @@ test_that("Design path must be a valid directory", {
test_that("Resps must be an integer", { test_that("Resps must be an integer", {
# Test case: resps is missing # Test case: resps is missing
expect_error(sim_all(nosim = nosim, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)) expect_error(sim_all(nosim = nosim, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff))
# Test case: resps is not an integer # Test case: resps is not an integer
expect_error(sim_all(nosim = nosim, resps = "abc", destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)) 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 # 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)) expect_error(sim_all(nosim = nosim, resps = 1.5, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff))
}) })
test_that("Function exists in simulateDCE", { test_that("Function exists in simulateDCE", {
...@@ -149,10 +149,10 @@ test_that("Function exists in simulateDCE", { ...@@ -149,10 +149,10 @@ test_that("Function exists in simulateDCE", {
}) })
test_that("Simulation results are reasonable", { test_that("Simulation results are reasonable", {
result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff) result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)
expect_gt(result1$est_bsq, -1) expect_gt(result1$est_bsq, -1)
expect_lt(result1$est_bsq, 1) expect_lt(result1$est_bsq, 1)
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment