From 474090cc1fd0bda0247fb8ba84a23096c8a2c84e Mon Sep 17 00:00:00 2001 From: ayogasekaram Date: Mon, 28 Oct 2024 17:31:42 +0000 Subject: [PATCH] add ard_categorical_ci.data.frame tests. --- .../test-ard_categorical_ci.data.frame.R | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/testthat/test-ard_categorical_ci.data.frame.R diff --git a/tests/testthat/test-ard_categorical_ci.data.frame.R b/tests/testthat/test-ard_categorical_ci.data.frame.R new file mode 100644 index 00000000..b2661a53 --- /dev/null +++ b/tests/testthat/test-ard_categorical_ci.data.frame.R @@ -0,0 +1,151 @@ +test_that("ard_categorical_ci.data.frame(method = 'wald')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "wald" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_wald(mtcars[["vs"]]) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'waldcc')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "waldcc" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_wald(mtcars[["vs"]], correct = TRUE) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'clopper-pearson')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "clopper-pearson" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_clopper_pearson(mtcars[["vs"]]) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'wilson')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "wilson" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_wilson(mtcars[["vs"]]) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'wilsoncc')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "wilsoncc" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_wilson(mtcars[["vs"]], correct = TRUE) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'strat_wilson')", { + skip_if_not(is_pkg_installed("broom")) + + mtcars$gear <- as.factor(mtcars$gear) + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + strata = "gear", + method = "strat_wilson" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_strat_wilson(mtcars[["vs"]], strata = as.factor(mtcars[["gear"]])) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'strat_wilsoncc')", { + skip_if_not(is_pkg_installed("broom")) + + mtcars$gear <- as.factor(mtcars$gear) + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + strata = "gear", + method = "strat_wilsoncc" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_strat_wilson(mtcars[["vs"]], strata = as.factor(mtcars[["gear"]]), correct = TRUE) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'jeffreys')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "jeffreys" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_jeffreys(mtcars[["vs"]]) |> + unlist() |> unname() + ) +}) + +test_that("ard_categorical_ci.data.frame(method = 'agresti-coull')", { + skip_if_not(is_pkg_installed("broom")) + + expect_equal( + ard_categorical_ci( + mtcars, + variables = vs, + method = "agresti-coull" + ) |> + dplyr::select(stat) |> unlist() |> unname(), + proportion_ci_agresti_coull(mtcars[["vs"]]) |> + unlist() |> unname() + ) +}) + +test_that("ard_continuous_ci.data.frame() follows ard structure", { + skip_if_not(is_pkg_installed("broom")) + + expect_silent( + ard_categorical_ci( + mtcars, + variables = vs, + method = "wald" + ) |> + cards::check_ard_structure() + ) +})