Skip to content
Snippets Groups Projects
Commit 92be7e92 authored by dj44vuri's avatar dj44vuri
Browse files

tests added

parent a8b05e20
Branches
No related tags found
No related merge requests found
......@@ -27,6 +27,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u){
stop(" 'resps' must be provided and must be an integer indicating the number of respondents per run.")
}
if (!dir.exists(designpath)) {
stop(" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified")
}
designfile<-list.files(designpath,full.names = T)
designname <- stringr::str_remove_all(list.files(designpath,full.names = F),
......
......@@ -8,7 +8,7 @@
#' @export
#'
#' @examples \dontrun{simulate_choices(datadet, utils,setspp)}
simulate_choices <- function(data=datadet, utility =utils, setspp, destype) { #the part in dataset that needs to be repeated in each run
simulate_choices <- function(data, utility, setspp, destype) { #the part in dataset that needs to be repeated in each run
......@@ -19,6 +19,7 @@ simulate_choices <- function(data=datadet, utility =utils, setspp, destype) { #
dplyr::transmute(!!formula.tools::lhs(equation) := !!formula.tools::rhs(equation) )
}
# Here one can add additional case-specific data
cat(" \n does sou_gis exist: ", exists("sou_gis"), "\n")
if (exists("sou_gis") && is.function(sou_gis)) {
......
......@@ -4,7 +4,7 @@
\alias{simulate_choices}
\title{Simulate choices based on a dataframe with a design}
\usage{
simulate_choices(data = datadet, utility = utils, setspp, destype)
simulate_choices(data, utility, setspp, destype)
}
\arguments{
\item{data}{a dataframe that includes a design repeated for the number of observations}
......
......@@ -3,7 +3,7 @@ rm(list=ls())
devtools::load_all()
set.seed(3393)
designpath<- system.file("extdata","Rbook" ,package = "simulateDCE")
......
......@@ -11,7 +11,7 @@ test_that("file does not exist", {
"does not exist in current working directory")
})
test_that("all is correct, but gives a warning", {
test_that("all is correct", {
expect_no_error(readdesign(design = design_path, designtype = "ngene"))
})
......
......@@ -6,7 +6,7 @@ designpath<- system.file("extdata","Rbook" ,package = "simulateDCE")
notes <- "No Heuristics"
resps =240 # number of respondents
resps =40 # number of respondents
nosim=2 # number of simulations to run (about 500 is minimum)
#betacoefficients should not include "-"
......@@ -47,3 +47,60 @@ test_that("no value provided for utility", {
designpath = designpath),
"must be provided and must be a list containing ")
})
test_that("wrong designtype", {
expect_error(sim_all(nosim = nosim, resps=resps, destype = "ng",
designpath = designpath, u=ul),"Invalid value for design. Please provide either 'ngene' or 'spdesign'.")
})
test_that("folder does not exist", {
expect_error(sim_all(nosim = nosim, resps=resps, destype = destype,
designpath = system.file("da/bullshit", package = "simulateDCE"), u=ul)
,
"The folder where your designs are stored does not exist.")
})
test_that("seed setting makes code reproducible", {
set.seed(3333)
bsq=0.00
bredkite=-0.05
bdistance=0.50
bcost=-0.05
bfarm2=0.25
bfarm3=0.50
bheight2=0.25
bheight3=0.50
result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul)
set.seed(3333)
bsq=0.00
bredkite=-0.05
bdistance=0.50
bcost=-0.05
bfarm2=0.25
bfarm3=0.50
bheight2=0.25
bheight3=0.50
result2 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul)
expect_identical(result1[["summaryall"]], result2[["summaryall"]])
})
test_that("No seed setting makes code results different", {
result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul)
result2 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul)
expect_failure(expect_identical(result1[["summaryall"]], result2[["summaryall"]]))
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment