diff --git a/tests/testthat/test-independent-testing-collect_n_subject.R b/tests/testthat/test-independent-testing-collect_n_subject.R index dbcb65f..185920d 100644 --- a/tests/testthat/test-independent-testing-collect_n_subject.R +++ b/tests/testthat/test-independent-testing-collect_n_subject.R @@ -1,5 +1,3 @@ -library(r2rtf) - test_that("test n_subject can calculate number of records by group in diffrent `use_na` situation", { df1 <- data.frame( id = c(1, 2, 3, 4, 5, 6, 7), diff --git a/tests/testthat/test-independent-testing-meta_adam.R b/tests/testthat/test-independent-testing-meta_adam.R index be520c0..9cc1bdf 100644 --- a/tests/testthat/test-independent-testing-meta_adam.R +++ b/tests/testthat/test-independent-testing-meta_adam.R @@ -1,6 +1,3 @@ -library(r2rtf) - - test_that("meta_adam testing", { test <- meta_adam( population = r2rtf::r2rtf_adsl, diff --git a/tests/testthat/test-independent-testing-meta_add_total.R b/tests/testthat/test-independent-testing-meta_add_total.R index 70c0a8c..daa126a 100644 --- a/tests/testthat/test-independent-testing-meta_add_total.R +++ b/tests/testthat/test-independent-testing-meta_add_total.R @@ -1,16 +1,12 @@ -library(testthat) -library(dplyr) - test_that("Multple names for total column has to throw error", { expect_error(meta_add_total(meta = meta_example(), total = c("Total", "Sum"))) }) - test_that("number of distinct treatment arms after adding", { x <- meta_add_total(meta = meta_example(), total = "Sum") y <- meta_example() - expect_equal(n_distinct(x$data_population$TRTA), n_distinct(y$data_population$TRTA) + 1) - expect_equal(n_distinct(x$data_observation$TRTA), n_distinct(y$data_observation$TRTA) + 1) + expect_equal(dplyr::n_distinct(x$data_population$TRTA), dplyr::n_distinct(y$data_population$TRTA) + 1) + expect_equal(dplyr::n_distinct(x$data_observation$TRTA), dplyr::n_distinct(y$data_observation$TRTA) + 1) expect_true("Sum" %in% x$data_observation$TRTA) expect_false("Sum" %in% y$data_observation$TRTA) expect_true("Sum" %in% x$data_population$TRTA) diff --git a/tests/testthat/test-independent-testing-meta_split.R b/tests/testthat/test-independent-testing-meta_split.R index 76f0753..77e2846 100644 --- a/tests/testthat/test-independent-testing-meta_split.R +++ b/tests/testthat/test-independent-testing-meta_split.R @@ -1,5 +1,3 @@ -library(dplyr) - test_that("variable 'RACE' checking", { expect_equal(names(meta_example() |> meta_split("RACE")), sort(unique(meta_example()$data_population$RACE))) }) @@ -7,41 +5,41 @@ test_that("variable 'RACE' checking", { test_that("variable 'RACE = WHITE' checking in data_population", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_population %>% filter(RACE == "WHITE") + z <- meta_example()$data_population %>% dplyr::filter(RACE == "WHITE") expect_equal(x$WHITE$data_population$USUBJID, unlist(as.list(z$USUBJID))) }) test_that("variable 'RACE = BLACK OR AFRICAN AMERICAN' checking in data_population", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_population %>% filter(RACE == "BLACK OR AFRICAN AMERICAN") + z <- meta_example()$data_population %>% dplyr::filter(RACE == "BLACK OR AFRICAN AMERICAN") expect_equal(x$`BLACK OR AFRICAN AMERICAN`$data_population$USUBJID, unlist(as.list(z$USUBJID))) }) test_that("variable 'RACE = AMERICAN INDIAN OR ALASKA NATIVE' checking in data_population", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_population %>% filter(RACE == "AMERICAN INDIAN OR ALASKA NATIVE") + z <- meta_example()$data_population %>% dplyr::filter(RACE == "AMERICAN INDIAN OR ALASKA NATIVE") expect_equal(x$`AMERICAN INDIAN OR ALASKA NATIVE`$data_population$USUBJID, unlist(as.list(z$USUBJID))) }) test_that("variable 'RACE = WHITE' checking in data_observation", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_observation %>% filter(RACE == "WHITE") + z <- meta_example()$data_observation %>% dplyr::filter(RACE == "WHITE") expect_equal(x$WHITE$data_observation$USUBJID, unlist(as.list(z$USUBJID))) }) test_that("variable 'RACE = BLACK OR AFRICAN AMERICAN' checking in data_observation", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_observation %>% filter(RACE == "BLACK OR AFRICAN AMERICAN") + z <- meta_example()$data_observation %>% dplyr::filter(RACE == "BLACK OR AFRICAN AMERICAN") expect_equal(x$`BLACK OR AFRICAN AMERICAN`$data_observation$USUBJID, unlist(as.list(z$USUBJID))) }) test_that("variable 'RACE = AMERICAN INDIAN OR ALASKA NATIVE' checking in data_observation", { x <- meta_example() |> meta_split("RACE") - z <- meta_example()$data_observation %>% filter(RACE == "AMERICAN INDIAN OR ALASKA NATIVE") + z <- meta_example()$data_observation %>% dplyr::filter(RACE == "AMERICAN INDIAN OR ALASKA NATIVE") expect_equal(x$`AMERICAN INDIAN OR ALASKA NATIVE`$data_observation$USUBJID, unlist(as.list(z$USUBJID))) }) diff --git a/tests/testthat/test-independent-testing-outdata.R b/tests/testthat/test-independent-testing-outdata.R index 5ad62cb..0126fc1 100644 --- a/tests/testthat/test-independent-testing-outdata.R +++ b/tests/testthat/test-independent-testing-outdata.R @@ -1,9 +1,6 @@ -library(dplyr) -library(metalite) - test_that("Its class is 'outdata'", { meta <- meta_example() - output <- outdata(meta_example(), "apat", "wk12", "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1, order = 1:3) + output <- outdata(meta_example(), "apat", "wk12", "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1, order = 1:3) expect_equal(class(output), "outdata") expect_equal(length(output), 8) @@ -17,7 +14,7 @@ test_that("Expecting an error", { test_that("Its class is 'outdata'", { meta <- meta_example() - x <- list(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1, order = 1:3) + x <- list(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1, order = 1:3) output <- metalite:::new_outdata(x) expect_equal(class(output), "outdata") }) @@ -27,14 +24,9 @@ test_that("Expecting an error", { meta <- meta_example() - expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = "Placebo", order = 1:3))) - - - expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1, order = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")))) - - expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = 1, observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1, order = 1:3))) - - expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1:2, order = 1:3))) - - expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = c("apat", "ITT"), observation = "wk12", parameter = "rel", n = meta$data_population %>% group_by(TRTA) %>% summarize(n = n()), group = "TRTA", reference_group = 1, order = 1:3))) + expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = "Placebo", order = 1:3))) + expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1, order = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")))) + expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = 1, observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1, order = 1:3))) + expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = "apat", observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1:2, order = 1:3))) + expect_error(metalite:::validate_outdata(outdata(meta = meta_example(), population = c("apat", "ITT"), observation = "wk12", parameter = "rel", n = meta$data_population %>% dplyr::group_by(TRTA) %>% dplyr::summarize(n = dplyr::n()), group = "TRTA", reference_group = 1, order = 1:3))) }) diff --git a/tests/testthat/test-independent-testing-plan.R b/tests/testthat/test-independent-testing-plan.R index 3ea7c44..5e62dca 100644 --- a/tests/testthat/test-independent-testing-plan.R +++ b/tests/testthat/test-independent-testing-plan.R @@ -1,6 +1,3 @@ -library(dplyr) - - test_that("error is thrown", { expect_error(metalite::plan(c("ae_summary", "ae_specific"), population = "apat", observation = c("wk12", "wk24"), parameter = "any;rel")) })