From 0c1de67f1d4f2236d97e706a4b99a89bdba8a0b3 Mon Sep 17 00:00:00 2001 From: samuelsmock <smock.samuel@gmail.com> Date: Wed, 7 Feb 2024 16:48:43 +0100 Subject: [PATCH] divergence fix --- R/sim_all.R | 14 +++++++------- tests/testthat/Rplots.pdf | Bin 234011 -> 234011 bytes tests/testthat/test-sim_all.R | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/R/sim_all.R b/R/sim_all.R index b0417e6..9d6b6b7 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 GIT binary patch delta 59 zcmbQegm3l|z6oZkMh51FW+rAv7Mfi8zWFIGi6yBD8ZK5w21X_ZaJk0l)@a7oXr`^v I%m*d{0Q8a&?*IS* delta 59 zcmbQegm3l|z6oZkhQ@}52F8}A2AW*@zWFIGi6yBD8ZK5w21X_ZaJk0l)@a7oXr`^v I%m*d{0P$!L)c^nh diff --git a/tests/testthat/test-sim_all.R b/tests/testthat/test-sim_all.R index 962ecbe..e4e4a9d 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) - + }) -- GitLab