forked from USEPA/CompTox-ToxCast-tcpl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tcplPlot bug when compare.val is set and number of plots is great…
…er than 1 Fixes USEPA#280 Add condition to handle `compare.val` with multiple plots in `tcplPlot` function. * **R/tcplPlot.R** - Add a condition to check if `compare.val` is set and the number of plots is greater than 1. - Modify the `if` condition to handle the case when `compare.val` is set and the number of plots is greater than 1. - Ensure that the function does not produce an error when `compare.val` is set and the number of plots is greater than 1. * **tests/testthat/test-plotting.R** - Add a test case to check if `tcplPlot` handles the case when `compare.val` is set and the number of plots is greater than 1. - Ensure that the test case verifies that the function does not produce an error in this scenario. - Add a test case to check if `tcplPlot` handles the case when `compare.val` is set and the number of plots is greater than 1 with `type` set to 'sc'.
- Loading branch information
1 parent
ceacf6a
commit 6bab63d
Showing
2 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
test_that("multiplication works", { | ||
expect_equal(2 * 2, 4) | ||
test_that("tcplPlot handles compare.val with multiple plots", { | ||
data("mc_test") | ||
mocked <- mc_test$plot_multiple_m4id_compare | ||
local_mocked_bindings( | ||
tcplQuery = function(query, db, tbl) { | ||
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery | ||
else mocked[query][[1]] | ||
} | ||
) | ||
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both | ||
expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) | ||
expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) | ||
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") | ||
expect_length(fn, 1) # exactly one file created | ||
file.remove(fn) # clean up | ||
}) | ||
|
||
test_that("tcplPlot handles compare.val with multiple plots and type = 'sc'", { | ||
data("sc_test") | ||
mocked <- sc_test$plot_multiple_s2id_compare | ||
local_mocked_bindings( | ||
tcplQuery = function(query, db, tbl) { | ||
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery | ||
else mocked[query][[1]] | ||
} | ||
) | ||
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both | ||
expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "pdf", verbose = FALSE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot_sc"))) | ||
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot_sc") | ||
expect_length(fn, 1) # exactly one file created | ||
file.remove(fn) # clean up | ||
}) |