Skip to content

Commit

Permalink
add snapshot tests for plot.tidyvpcobj
Browse files Browse the repository at this point in the history
  • Loading branch information
certara-jcraig committed Aug 16, 2023
1 parent 87cd11f commit 2307998
Show file tree
Hide file tree
Showing 9 changed files with 9,182 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Suggests:
remotes,
vpc,
rmarkdown,
testthat (>= 2.1.0)
testthat (>= 2.1.0),
vdiffr (>= 1.0.0)
License: MIT + file LICENSE
LazyData: true
Encoding: UTF-8
Expand Down
548 changes: 548 additions & 0 deletions tests/testthat/_snaps/plot/bins-without-stats.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
538 changes: 538 additions & 0 deletions tests/testthat/_snaps/plot/bins-ypc-without-stats.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,876 changes: 1,876 additions & 0 deletions tests/testthat/_snaps/plot/censored-plot-with-aql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,436 changes: 2,436 additions & 0 deletions tests/testthat/_snaps/plot/censored-plot-with-bql-aql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,890 changes: 1,890 additions & 0 deletions tests/testthat/_snaps/plot/censored-plot-with-bql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
891 changes: 891 additions & 0 deletions tests/testthat/_snaps/plot/one-sided-strat-formula-with-facet-wrap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
895 changes: 895 additions & 0 deletions tests/testthat/_snaps/plot/two-sided-strat-formula-with-facet-grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
get_os <- function(){
sysinf <- Sys.info()
if (!is.null(sysinf)){
os <- sysinf['sysname']
if (os == 'Darwin')
os <- "osx"
} else { ## mystery machine
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
if (grepl("linux-gnu", R.version$os))
os <- "linux"
}
tolower(os)
}

test_that("plot.tidyvpcobj plots binning without stats", {
testthat::skip_if_not(get_os() == "windows")
testthat::skip_on_cran()

obs_data <- obs_data[MDV == 0]
sim_data <- sim_data[MDV == 0]
obs_data$PRED <- sim_data[REP == 1, PRED]

vpc <- observed(obs_data, x = TIME, y = DV)
vpc <- simulated(vpc, sim_data, y = DV)
vpc <- binning(vpc, bin = NTIME)

options(warn = -1)
vdiffr::expect_doppelganger("Bins without stats",
plot(vpc))

vpc <- predcorrect(vpc, pred = PRED)
vdiffr::expect_doppelganger("Bins ypc without stats",
plot(vpc))
options(warn = 0)

})


test_that("plot.tidyvpcobj plots censoring", {
testthat::skip_if_not(get_os() == "windows")
testthat::skip_on_cran()

obs_data <- obs_data[MDV == 0]
sim_data <- sim_data[MDV == 0]
obs_data$LLOQ <- obs_data[, ifelse(STUDY == "Study A", 50, 25)]
obs_data$ULOQ <- obs_data[, ifelse(STUDY == "Study A", 125, 100)]

vpc <- observed(obs_data, x = TIME, y = DV)
vpc <- simulated(vpc, sim_data, y = DV)
vpc <- censoring(vpc, blq = DV < LLOQ, lloq = LLOQ, alq = DV > ULOQ, uloq = ULOQ)
vpc <-stratify(vpc, ~ STUDY)
vpc <- binning(vpc, bin = NTIME)
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9))

options(warn = -1)
vdiffr::expect_doppelganger("Censored plot with bql",
plot(vpc, censoring.type = "blq"))

vdiffr::expect_doppelganger("Censored plot with aql",
plot(vpc, censoring.type = "alq"))

vdiffr::expect_doppelganger("Censored plot with bql aql",
plot(vpc, censoring.type = "both"))

plot_list <- plot(vpc, censoring.type = "both", censoring.output = "list")
testthat::expect_true(length(plot_list) == 3)
testthat::expect_true(all(sapply(plot_list, ggplot2::is.ggplot)))

plot_grid <- plot(vpc, censoring.type = "both", censoring.output = "grid", nrow = 1, ncol = 3)
testthat::expect_true(inherits(plot_grid, "egg"))
options(warn = 0)

})

test_that("plot.tidyvpcobj plots stratified", {
testthat::skip_if_not(get_os() == "windows")
testthat::skip_on_cran()

obs_data <- obs_data[MDV == 0]
sim_data <- sim_data[MDV == 0]

options(warn = -1)
#two-sided strat formula
vpc <- observed(obs_data, x = TIME, y = DV)
vpc <- simulated(vpc, sim_data, y = DV)
vpc <- stratify(vpc, GENDER ~ STUDY)
vpc <- binning(vpc, bin = NTIME)
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9), quantile.type = 6)

vdiffr::expect_doppelganger("Two sided strat formula with facet_grid",
plot(vpc))

#one-sided strat formula
vpc <- observed(obs_data, x = TIME, y = DV)
vpc <- simulated(vpc, sim_data, y = DV)
vpc <- stratify(vpc, ~ GENDER + STUDY)
vpc <- binless(vpc)
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9), quantile.type = 6)

vdiffr::expect_doppelganger("One sided strat formula with facet_wrap",
plot(vpc))
options(warn = 0)
})

0 comments on commit 2307998

Please sign in to comment.