Skip to content

Commit

Permalink
fix(tests): change storing format of model object files from .json to…
Browse files Browse the repository at this point in the history
… .RDS and updates test_visualization accordingly
  • Loading branch information
ntorresd committed Aug 15, 2023
1 parent ec4335c commit 034e63e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 86 deletions.
114 changes: 57 additions & 57 deletions tests/testthat/_snaps/visualisation/plot-arrange-simdata-foi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testthat/extdata/model_constant.RDS
Binary file not shown.
1 change: 0 additions & 1 deletion tests/testthat/extdata/model_constant.json

This file was deleted.

Binary file added tests/testthat/extdata/model_tv_normal.RDS
Binary file not shown.
1 change: 0 additions & 1 deletion tests/testthat/extdata/model_tv_normal.json

This file was deleted.

Binary file added tests/testthat/extdata/model_tv_normal_log.RDS
Binary file not shown.
1 change: 0 additions & 1 deletion tests/testthat/extdata/model_tv_normal_log.json

This file was deleted.

16 changes: 8 additions & 8 deletions tests/testthat/models_serialization.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
library(devtools)
library(dplyr)
library(serofoi)
library(testthat)

set.seed(1234) # For reproducibility

#----- Read and prepare data
data("simdata_large_epi")
simdata <- simdata_large_epi %>% prepare_serodata()
simdata <- prepare_serodata(simdata_large_epi)
no_transm <- 0.0000000001
big_outbreak <- 1.5
foi_sim <- c(rep(no_transm, 32), rep(big_outbreak, 3), rep(no_transm, 15)) # 1 epidemics
Expand All @@ -23,11 +22,12 @@ models_list <- lapply(models_to_run,
serodata = simdata,
n_iters = 1000)

model_constant_json <- jsonlite::serializeJSON(models_list[[1]])
write_json(model_constant_json, testthat::test_path("extdata", "model_constant.json"))
saveRDS(models_list[[1]],
testthat::test_path("extdata", "model_constant.RDS"))

model_tv_normal_json <- jsonlite::serializeJSON(models_list[[2]])
write_json(model_tv_normal_json, testthat::test_path("extdata", "model_tv_normal.json"))
saveRDS(models_list[[2]],
testthat::test_path("extdata", "model_tv_normal.RDS"))

saveRDS(models_list[[3]],
testthat::test_path("extdata", "model_tv_normal_log.RDS"))

model_tv_normal_log_json <- jsonlite::serializeJSON(models_list[[3]])
write_json(model_tv_normal_json, testthat::test_path("extdata", "model_tv_normal_log.json"))
33 changes: 15 additions & 18 deletions tests/testthat/test_visualisation.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,25 @@ test_that("individual models", {
size_text <- 6
max_lambda <- 1.55

model_constant_json <- jsonlite::fromJSON(testthat::test_path("extdata", "model_constant.json"))
model_constant <- jsonlite::unserializeJSON(model_constant_json)
constant_plot <- plot_seromodel(model_constant,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
model_constant <- readRDS(testthat::test_path("extdata", "model_constant.RDS"))
constant_plot <- plot_seromodel(seromodel_object = model_constant,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
)

model_tv_normal_json <- fromJSON(testthat::test_path("extdata", "model_tv_normal.json"))
model_tv_normal <- jsonlite::unserializeJSON(model_tv_normal_json)
tv_normal_plot <- plot_seromodel(model_tv_normal,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
model_tv_normal <- readRDS(testthat::test_path("extdata", "model_tv_normal.RDS"))
tv_normal_plot <- plot_seromodel(seromodel_object = model_tv_normal,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
)

model_tv_normal_log_json <- fromJSON(testthat::test_path("extdata", "model_tv_normal_log.json"))
model_tv_normal_log <- jsonlite::unserializeJSON(model_tv_normal_log_json)
tv_normal_log_plot <- plot_seromodel(model_tv_normal_log,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
model_tv_normal_log <- readRDS(testthat::test_path("extdata", "model_tv_normal_log.RDS"))
tv_normal_log_plot <- plot_seromodel(seromodel_object = model_tv_normal_log,
size_text = size_text,
max_lambda = max_lambda,
foi_sim = foi_sim
)

plot_arrange <- cowplot::plot_grid(constant_plot,
Expand Down

0 comments on commit 034e63e

Please sign in to comment.