# test the gather_simulation functionality
# test the patterns2lines function
test_that("patterns2lines() finds correct line where data starts", {
# set number of parameters
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
# get list of files generated by make_bunch_of_files()
file_list <- list.files(pattern="sim_test")
# take the first file and get some lines out of it
lines <- patterns2lines(filename = file_list[[1]]
,pattern_from = "par.a"
,pattern_to = NA)
# print(readLines(file_list[[1]]))
# if there are 100 lines of data + header
# we have 101 lines of data
# then an empty line on line 102
# hence params start on line 103
expect_equal(lines[1], 103)
})
test_that("summarize.sims() finds correct number of files in non-nested dirs", {
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
summary_data <- summarize.sims(
simulations_path="."
,sep=";"
,parameter_start_pattern="par.a"
,parameter_end_pattern=NA
,data_start_pattern = "a"
,data_end_pattern = "^$"
)
expect_equal(nrow(summary_data), 20)
})
test_that("colnums: summarize.sims() finds correct number of columns in non-nested dirs", {
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
summary_data <- summarize.sims(
simulations_path="."
,sep=";"
,parameter_start_pattern="par.a"
,parameter_end_pattern=NA
,data_start_pattern = "a"
,data_end_pattern = "^$"
)
# we would expect number columns to be n_cols data + n_param == 20
# but there is an additional column for file names, hence 21
expect_equal(ncol(summary_data), 21)
})
test_that("summarize.sims() finds correct final row", {
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
summary_data <- summarize.sims(
simulations_path="."
,sep=";"
,parameter_start_pattern="par.a"
,parameter_end_pattern=NA
,data_start_pattern = "a"
,data_end_pattern = "^$"
)
# first column should be 100 time steps
expect_equal(summary_data[1,"a"],100)
})
test_that("summarize.sims() finds correct first parameter", {
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
summary_data <- summarize.sims(
simulations_path="."
,sep=";"
,parameter_start_pattern="par.a"
,parameter_end_pattern=NA
,data_start_pattern = "a"
,data_end_pattern = "^$"
)
# check whether first parameter is in there
expect_equal("par.a" %in% names(summary_data),T)
})
test_that("summarize.sims() finds correct final parameter", {
n_param <- 10
# make a bunch of simulated files to summarize
make_bunch_of_files(nested_dirs=F
,n_files=20
,n_cols=10
,n_params=n_param)
summary_data <- summarize.sims(
simulations_path="."
,sep=";"
,parameter_start_pattern="par.a"
,parameter_end_pattern=NA
,data_start_pattern = "a"
,data_end_pattern = "^$"
)
print(names(summary_data))
final_expected_param <- paste0("par.",letters[n_param])
# check whether final parameter is in there
expect_equal(final_expected_param %in% names(summary_data),T)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.