From 97c8a836c276d63dcf507b0a041ef40487a84f61 Mon Sep 17 00:00:00 2001 From: samuelsmock <smock.samuel@gmail.com> Date: Wed, 14 Feb 2024 18:58:44 -0600 Subject: [PATCH] added a few new tests on test that output --- tests/manual-tests/agora.R | 2 +- tests/manual-tests/feedadditives.R | 47 +++++++++++++++++++++++++++++ tests/testthat/Rplots.pdf | Bin 234011 -> 234011 bytes tests/testthat/test-sim_all.R | 17 +++++++++-- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/manual-tests/feedadditives.R diff --git a/tests/manual-tests/agora.R b/tests/manual-tests/agora.R index 1e403d0..7e153cd 100644 --- a/tests/manual-tests/agora.R +++ b/tests/manual-tests/agora.R @@ -15,7 +15,7 @@ bcoeff <- list( basc = -1.2, basc2 = -1.4, baction = 0.1, - badvisory = 0.4, + badvisory =0.4, bpartner = 0.3, bcomp = 0.02) diff --git a/tests/manual-tests/feedadditives.R b/tests/manual-tests/feedadditives.R new file mode 100644 index 0000000..6892e21 --- /dev/null +++ b/tests/manual-tests/feedadditives.R @@ -0,0 +1,47 @@ +rm(list=ls()) +devtools::load_all() + +designpath<- system.file("extdata","feedadditives" ,package = "simulateDCE") + +#notes <- "This design consists of different heuristics. One group did not attend the methan attribute, another group only decided based on the payment" + +notes <- "Three heuristics" + +resps =300 # number of respondents +nosim=2 # number of simulations to run (about 500 is minimum) + +#betacoefficients should not include "-" +basc = 0.2 +bcow = 0.3 +badv = 0.3 +bvet = 0.3 +bfar = 0.3 +bmet = 0.3 +bbon = 0.3 +bbon2 = 1.9 +basc2 =2 + +decisiongroups=c(0,0.3,0.6,0.8,1) + +#place your utility functions here +u<- list(u1= list( + v1 =V.1 ~ bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bmet*alt1.met + bbon * alt1.bon, + v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bmet*alt2.met + bbon * alt2.bon, + v3 =V.3 ~ basc) + , + u2 = list( + v1 =V.1 ~ bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bbon * alt1.bon, + v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bbon * alt2.bon, + v3 =V.3 ~ basc), + u3 = list( + v1 =V.1 ~ bbon2 * alt1.bon, + v2 =V.2 ~ bbon2 * alt2.bon, + v3 =V.3 ~ basc), + + u4 = list(v1 =V.1 ~ basc2 + bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bmet*alt1.met + bbon * alt1.bon, + v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bmet*alt2.met + bbon * alt2.bon, + v3 =V.3 ~ basc) + + + +) diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index e9033a3ec9ebb6184785100f40f6b08f70370f59..9b70e176fb2a5eae21b9608d833b66ae35a70572 100644 GIT binary patch delta 63 zcmbQegm3l|z6s_kh9-t4rp6|wnq2z6`6(`mC8-J;E>=bcMkWSEFu94*I*i7R9jzUV NtsP8TJD4X=1OPit5`q8# delta 63 zcmbQegm3l|z6s_k1{OeQZeXs-rSF@c;*waBs-WRwWn^GvVqgT5n;5ObXw=xz+QHb` L!L+r5dGbU6JSP%| diff --git a/tests/testthat/test-sim_all.R b/tests/testthat/test-sim_all.R index 381e35d..2df09e8 100644 --- a/tests/testthat/test-sim_all.R +++ b/tests/testthat/test-sim_all.R @@ -153,7 +153,7 @@ test_that("Simulation results are reasonable", { result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff) ## The function below is intended to find a dataframe called $coef in the output - ## regardless of the output data structure which can vary + ## regardless of the output data structure, which can vary find_dataframe <- function(list_object, dataframe_name) { # Check if the current object is a list if (is.list(list_object)) { @@ -182,12 +182,25 @@ test_that("Simulation results are reasonable", { for (variable in names(bcoeff)){ ### Compare singular input value (hypothesis) with the average value of all iterations. ### - ### This could be made more rigorous by testing each iteration or by changing the ### + ### This could be made more rigorous by testing each iteration rather than the mean or by changing the ### ### tolerance around the input value considered valid. input_value <- bcoeff[[variable]] mean_output_value <- mean(coeffNestedOutput[[paste0("est_", variable)]]) ## access the mean value of each iteration + + ##change this depending on how rigorous you want to be + # Check if variable exists in coeffNestedOutput + expect_true(paste0("est_", variable) %in% names(coeffNestedOutput), + sprintf("Variable est_%s does not exist in coeffNestedOutput", variable)) + + # Check if variable is numeric + expect_type(coeffNestedOutput[[paste0("est_", variable)]], "numeric", + sprintf("Variable est_%s in coeffNestedOutput is not numeric", variable)) + + # Check if each entry in the variable column is numeric + expect_true(all(sapply(coeffNestedOutput[[paste0("est_", variable)]], is.numeric)), + sprintf("Variable est_%s in coeffNestedOutput contains non-numeric values", variable)) expect_gt(mean_output_value, input_value - 1) expect_lt(mean_output_value, input_value + 1) } -- GitLab