-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Merck/self-contained-tests
Make tests self-contained
- Loading branch information
Showing
6 changed files
with
72 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Helper functions used by test-ae_forestly.R | ||
|
||
test_ae_forestly <- function() { | ||
metalite.ae::meta_ae_example() |> | ||
prepare_ae_forestly( | ||
population = "apat", | ||
observation = "wk12", | ||
parameter = "any;rel;ser" | ||
) |> | ||
format_ae_forestly(display = c("n", "prop", "fig_prop")) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Helper functions used by test-format_ae_forestly.R | ||
|
||
test_format_ae_forestly <- function() { | ||
prepare_ae_forestly( | ||
metalite.ae::meta_ae_example(), | ||
population = "apat", | ||
observation = "wk12", | ||
parameter = "any;rel;ser" | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Helper functions used by test-independent-testing-meta_forestly.R | ||
|
||
test_meta_forestly_1 <- function() { | ||
adsl <- r2rtf::r2rtf_adsl |> dplyr::mutate(TRTA = TRT01A) | ||
adae <- r2rtf::r2rtf_adae | ||
|
||
meta_forestly( | ||
adsl, | ||
adae, | ||
population_term = "apat", | ||
observation_term = "wk12", | ||
parameter_term = "any;rel;ser" | ||
) | ||
} | ||
|
||
test_meta_forestly_2 <- function() { | ||
adsl <- r2rtf::r2rtf_adsl |> dplyr::mutate(TRTA = TRT01A) | ||
adae <- r2rtf::r2rtf_adae | ||
|
||
meta_forestly( | ||
adsl, adae, | ||
population_term = "trt", | ||
population_subset = TRTFL == "Y", | ||
observation_term = "trtem", | ||
observation_subset = TRTEMFL == "Y" & TRTFL == "Y", | ||
parameter_term = "any;g35" | ||
) | ||
} |
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,26 +1,19 @@ | ||
tmp <- metalite.ae::meta_ae_example() |> | ||
prepare_ae_forestly( | ||
population = "apat", | ||
observation = "wk12", | ||
parameter = "any;rel;ser" | ||
) | ||
|
||
outdata <- tmp |> format_ae_forestly(display = c("n", "prop", "fig_prop")) | ||
|
||
test_that("ae_forestly(): default setting can be executed without error", { | ||
outdata <- test_ae_forestly() | ||
html <- outdata |> ae_forestly() | ||
html <- html[[length(html)]] | ||
|
||
testthat::expect_equal(html$name, "div") | ||
testthat::expect_equal(html$attribs$class, "container-fluid crosstalk-bscols") | ||
testthat::expect_true(grepl("width:1400px", html$children[[1]], fixed = TRUE)) | ||
testthat::expect_true(grepl("Incidence (%) in One or More Treatment Groups", html$children[[1]], fixed = TRUE)) | ||
expect_equal(html$name, "div") | ||
expect_equal(html$attribs$class, "container-fluid crosstalk-bscols") | ||
expect_true(grepl("width:1400px", html$children[[1]], fixed = TRUE)) | ||
expect_true(grepl("Incidence (%) in One or More Treatment Groups", html$children[[1]], fixed = TRUE)) | ||
}) | ||
|
||
test_that("ae_forestly(): test filter and width option", { | ||
outdata <- test_ae_forestly() | ||
html <- outdata |> ae_forestly(filter = c("n"), width = 1500) | ||
html <- html[[length(html)]] | ||
|
||
testthat::expect_true(grepl("width:1500px", html$children[[1]], fixed = TRUE)) | ||
testthat::expect_true(grepl("Number of AE in One or More Treatment Groups", html$children[[1]], fixed = TRUE)) | ||
expect_true(grepl("width:1500px", html$children[[1]], fixed = TRUE)) | ||
expect_true(grepl("Number of AE in One or More Treatment Groups", html$children[[1]], fixed = TRUE)) | ||
}) |
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,61 +1,49 @@ | ||
# Create input object | ||
adsl <- r2rtf::r2rtf_adsl |> dplyr::mutate(TRTA = TRT01A) | ||
adae <- r2rtf::r2rtf_adae | ||
|
||
# Test 1 | ||
test1 <- meta_forestly( | ||
adsl, | ||
adae, | ||
population_term = "apat", | ||
observation_term = "wk12", | ||
parameter_term = "any;rel;ser" | ||
) | ||
|
||
test_that("There is 1 analysis in the output: ae_forestly", { | ||
test1 <- test_meta_forestly_1() | ||
expect_equal(names(test1$analysis), c("ae_forestly")) | ||
}) | ||
|
||
test_that("There is 1 population: apat", { | ||
test1 <- test_meta_forestly_1() | ||
expect_equal(names(test1$population), "apat") | ||
}) | ||
|
||
test_that("There is 1 observation: wk12", { | ||
test1 <- test_meta_forestly_1() | ||
expect_equal(names(test1$observation), c("wk12")) | ||
}) | ||
|
||
test_that("There are 3 observations: any, rel, ser", { | ||
test1 <- test_meta_forestly_1() | ||
expect_equal(names(test1$parameter), c("any", "rel", "ser")) | ||
}) | ||
|
||
test_that("The output is a list", { | ||
test1 <- test_meta_forestly_1() | ||
expect_type(test1, "list") | ||
}) | ||
|
||
# Test 2 | ||
test2 <- meta_forestly(adsl, adae, | ||
population_term = "trt", | ||
population_subset = TRTFL == "Y", | ||
observation_term = "trtem", | ||
observation_subset = TRTEMFL == "Y" & TRTFL == "Y", | ||
parameter_term = "any;g35" | ||
) | ||
|
||
test_that("There is 1 population: trt", { | ||
test2 <- test_meta_forestly_2() | ||
expect_equal(names(test2$population), "trt") | ||
}) | ||
|
||
test_that("There is 1 population subset criteria: TRTFL == Y", { | ||
test2 <- test_meta_forestly_2() | ||
expect_equal(test2$population$trt$subset, quote(TRTFL == "Y")) | ||
}) | ||
|
||
test_that("There is 1 observation: trtem", { | ||
test2 <- test_meta_forestly_2() | ||
expect_equal(names(test2$observation), "trtem") | ||
}) | ||
|
||
test_that("There is 1 observation subset criteria: TREMTFL == Y & TRTFL == Y", { | ||
test2 <- test_meta_forestly_2() | ||
expect_equal(test2$observation$trtem$subset, quote(TRTEMFL == "Y" & TRTFL == "Y")) | ||
}) | ||
|
||
test_that("There are 2 observations: any, g35", { | ||
test2 <- test_meta_forestly_2() | ||
expect_equal(names(test2$parameter), c("any", "g35")) | ||
}) |