Skip to content

Commit e1680ae

Browse files
committed
311 add unit tests for loec for single, small/large and mixed compare
1 parent 0a6464b commit e1680ae

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/testthat/test-tcplPlot.R

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,73 @@ test_that("ggplot output returns specific warnings and errors", {
760760
})
761761

762762

763+
#-------------------------------------------------------------------------------
764+
# loec plotting tests
765+
#-------------------------------------------------------------------------------
766+
test_that("loec plotting works for single plot", {
767+
data("mc_test")
768+
mocked <- mc_test$plot_single_m4id
769+
local_mocked_bindings(
770+
tcplQuery = function(query, db, tbl) {
771+
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
772+
else mocked[query][[1]]
773+
}
774+
)
775+
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
776+
dat <- tcplPlotLoadData(val = mocked$m4id, flags = TRUE)
777+
dat[, c("modl", "fitc", "model_type", "hitc", "bmr", "bmd", "ac50") := list("loec", 100L, 1, 1, NA, NA, NA)]
778+
dat$loec <- sort(unlist(dat$conc), decreasing = TRUE)[1] # set loec to highest tested conc
779+
expect_no_error(tcplPlot(dat = dat, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))
780+
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
781+
expect_length(fn, 1) # exactly one file created
782+
file.remove(fn) # clean up
783+
})
784+
785+
test_that("loec plotting works for small comparison plot", {
786+
data("mc_test")
787+
mocked <- mc_test$plot_single_m4id_compare
788+
local_mocked_bindings(
789+
tcplQuery = function(query, db, tbl) {
790+
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
791+
else mocked[query][[1]]
792+
}
793+
)
794+
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
795+
dat <- tcplPlotLoadData(val = mocked$m4id, flags = TRUE)
796+
dat[, c("modl", "fitc", "model_type", "hitc", "bmr", "bmd", "ac50") := list("loec", 100L, 1, 1, NA, NA, NA)]
797+
dat$loec <- sort(unlist(dat$conc), decreasing = TRUE)[1:2] # set loec to highest tested concs
798+
expect_no_error(tcplPlot(dat = dat, compare = "chnm", output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))
799+
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
800+
expect_length(fn, 1) # exactly one file created
801+
file.remove(fn) # clean up
802+
})
803+
804+
test_that("loec plotting works for large comparison plot", {
805+
data("mc_test")
806+
mocked <- mc_test$plot_multiple_aeid_compare
807+
local_mocked_bindings(
808+
tcplQuery = function(query, db, tbl) {
809+
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
810+
else mocked[query][[1]]
811+
}
812+
)
813+
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
814+
dat_copy <- dat <- tcplPlotLoadData(fld = "aeid", val = mocked$aeid, flags = TRUE)
815+
dat <- dat[1:4]
816+
dat[, c("modl", "fitc", "model_type", "hitc", "bmr", "bmd", "ac50") := list("loec", 100L, 1, 1, NA, NA, NA)]
817+
dat$loec <- c(sort(unlist(dat$conc), decreasing = TRUE)[1:4], rep(NA, nrow(dat) - 4))
818+
expect_no_error(tcplPlot(dat = dat, compare = "conc_unit", output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot", group.threshold = 8))
819+
expect_no_error(tcplPlot(dat = dat, compare = "conc_unit", output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))
820+
dat <- dat_copy
821+
dat[, c("modl", "fitc", "model_type", "hitc", "bmr", "bmd", "ac50") := list("loec", 100L, 1, 1, NA, NA, NA)]
822+
dat$loec <- c(sort(unlist(dat$conc), decreasing = TRUE)[1:4], rep(NA, nrow(dat) - 4))
823+
expect_no_error(tcplPlot(dat = dat, compare = "conc_unit", output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot", group.threshold = 8))
824+
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
825+
expect_length(fn, 1) # exactly one file created
826+
file.remove(fn) # clean up
827+
})
828+
829+
763830
#-------------------------------------------------------------------------------
764831
# Covers testing tcplLoadData with "API" driver
765832
# Using httptest mocking to automatically save json responses from http requests

0 commit comments

Comments
 (0)