diff --git a/tests/testthat/_snaps/analyze_variables.md b/tests/testthat/_snaps/analyze_variables.md index 705312763c..4fe6f5d8ed 100644 --- a/tests/testthat/_snaps/analyze_variables.md +++ b/tests/testthat/_snaps/analyze_variables.md @@ -1,217 +1,3 @@ -# control_analyze_vars works with customized parameters - - Code - res - Output - $conf_level - [1] 0.9 - - $quantiles - [1] 0.1 0.9 - - $quantile_type - [1] 2 - - $test_mean - [1] 0 - - -# summary_formats works as expected - - Code - res - Output - n sum mean - "xx." "xx.x" "xx.x" - sd se mean_sd - "xx.x" "xx.x" "xx.x (xx.x)" - mean_se mean_ci mean_sei - "xx.x (xx.x)" "(xx.xx, xx.xx)" "(xx.xx, xx.xx)" - mean_sdi mean_pval median - "(xx.xx, xx.xx)" "xx.xx" "xx.x" - mad median_ci quantiles - "xx.x" "(xx.xx, xx.xx)" "xx.x - xx.x" - iqr range min - "xx.x" "xx.x - xx.x" "xx.x" - max median_range cv - "xx.x" "xx.x (xx.x - xx.x)" "xx.x" - geom_mean geom_mean_ci geom_cv - "xx.x" "(xx.xx, xx.xx)" "xx.x" - ---- - - Code - res - Output - $n - [1] "xx." - - $count - [1] "xx." - - $count_fraction - function(x, ...) { - attr(x, "label") <- NULL - - if (any(is.na(x))) { - return("NA") - } - - checkmate::assert_vector(x) - checkmate::assert_integerish(x[1]) - assert_proportion_value(x[2], include_boundaries = TRUE) - - result <- if (x[1] == 0) { - "0" - } else { - paste0(x[1], " (", round(x[2] * 100, 1), "%)") - } - - return(result) - } - - - $n_blq - [1] "xx." - - $pval - [1] "x.xxxx | (<0.0001)" - - -# summary_labels works as expected - - Code - res - Output - n sum - "n" "Sum" - mean sd - "Mean" "SD" - se mean_sd - "SE" "Mean (SD)" - mean_se mean_ci - "Mean (SE)" "Mean 95% CI" - mean_sei mean_sdi - "Mean -/+ 1xSE" "Mean -/+ 1xSD" - mean_pval median - "Mean p-value (H0: mean = 0)" "Median" - mad median_ci - "Median Absolute Deviation" "Median 95% CI" - quantiles iqr - "25% and 75%-ile" "IQR" - range min - "Min - Max" "Minimum" - max median_range - "Maximum" "Median (Min - Max)" - cv geom_mean - "CV (%)" "Geometric Mean" - geom_mean_ci geom_cv - "Geometric Mean 95% CI" "CV % Geometric Mean" - ---- - - Code - res - Output - n count - "n" "count" - count_fraction n_blq - "count_fraction" "n_blq" - pval - "p-value (chi-squared test)" - -# summary_custom works as expected - - Code - res - Output - $stats - [1] "n" "sum" "mean" "sd" "se" - [6] "mean_sd" "mean_se" "mean_ci" "mean_sei" "mean_sdi" - [11] "mean_pval" "median" "mad" "median_ci" "quantiles" - [16] "iqr" "range" "min" "max" "median_range" - [21] "cv" "geom_mean" "geom_mean_ci" "geom_cv" - - $formats - n sum mean - "xx." "xx.x" "xx.x" - sd se mean_sd - "xx.x" "xx.x" "xx.x (xx.x)" - mean_se mean_ci mean_sei - "xx.x (xx.x)" "(xx.xx, xx.xx)" "(xx.xx, xx.xx)" - mean_sdi mean_pval median - "(xx.xx, xx.xx)" "xx.xx" "xx.x" - mad median_ci quantiles - "xx.x" "(xx.xx, xx.xx)" "xx.x - xx.x" - iqr range min - "xx.x" "xx.x - xx.x" "xx.x" - max median_range cv - "xx.x" "xx.x (xx.x - xx.x)" "xx.x" - geom_mean geom_mean_ci geom_cv - "xx.x" "(xx.xx, xx.xx)" "xx.x" - - $labels - n sum - "n" "Sum" - mean sd - "Mean" "SD" - se mean_sd - "SE" "Mean (SD)" - mean_se mean_ci - "Mean (SE)" "Mean 95% CI" - mean_sei mean_sdi - "Mean -/+ 1xSE" "Mean -/+ 1xSD" - mean_pval median - "Mean p-value (H0: mean = 0)" "Median" - mad median_ci - "Median Absolute Deviation" "Median 95% CI" - quantiles iqr - "25% and 75%-ile" "IQR" - range min - "Min - Max" "Minimum" - max median_range - "Maximum" "Median (Min - Max)" - cv geom_mean - "CV (%)" "Geometric Mean" - geom_mean_ci geom_cv - "Geometric Mean 95% CI" "CV % Geometric Mean" - - $indent_mods - n sum mean sd se mean_sd - 0 0 0 0 0 0 - mean_se mean_ci mean_sei mean_sdi mean_pval median - 0 0 0 0 0 0 - mad median_ci quantiles iqr range min - 0 0 0 0 0 0 - max median_range cv geom_mean geom_mean_ci geom_cv - 0 0 0 0 0 0 - - ---- - - Code - res - Output - $stats - [1] "n" "count" - - $formats - $formats$n - [1] "xx.xx" - - $formats$count - [1] "xx." - - - $labels - n count - "n" "#" - - $indent_mods - n count - 2 2 - - # s_summary return NA for x length 0L Code diff --git a/tests/testthat/_snaps/summary_stats.md b/tests/testthat/_snaps/summary_stats.md new file mode 100644 index 0000000000..4dd4633f57 --- /dev/null +++ b/tests/testthat/_snaps/summary_stats.md @@ -0,0 +1,214 @@ +# summary_formats works as expected + + Code + res + Output + n sum mean + "xx." "xx.x" "xx.x" + sd se mean_sd + "xx.x" "xx.x" "xx.x (xx.x)" + mean_se mean_ci mean_sei + "xx.x (xx.x)" "(xx.xx, xx.xx)" "(xx.xx, xx.xx)" + mean_sdi mean_pval median + "(xx.xx, xx.xx)" "xx.xx" "xx.x" + mad median_ci quantiles + "xx.x" "(xx.xx, xx.xx)" "xx.x - xx.x" + iqr range min + "xx.x" "xx.x - xx.x" "xx.x" + max median_range cv + "xx.x" "xx.x (xx.x - xx.x)" "xx.x" + geom_mean geom_mean_ci geom_cv + "xx.x" "(xx.xx, xx.xx)" "xx.x" + +--- + + Code + res + Output + $n + [1] "xx." + + $count + [1] "xx." + + $count_fraction + function(x, ...) { + attr(x, "label") <- NULL + + if (any(is.na(x))) { + return("NA") + } + + checkmate::assert_vector(x) + checkmate::assert_integerish(x[1]) + assert_proportion_value(x[2], include_boundaries = TRUE) + + result <- if (x[1] == 0) { + "0" + } else { + paste0(x[1], " (", round(x[2] * 100, 1), "%)") + } + + return(result) + } + + + $n_blq + [1] "xx." + + $pval + [1] "x.xxxx | (<0.0001)" + + +# summary_labels works as expected + + Code + res + Output + n sum + "n" "Sum" + mean sd + "Mean" "SD" + se mean_sd + "SE" "Mean (SD)" + mean_se mean_ci + "Mean (SE)" "Mean 95% CI" + mean_sei mean_sdi + "Mean -/+ 1xSE" "Mean -/+ 1xSD" + mean_pval median + "Mean p-value (H0: mean = 0)" "Median" + mad median_ci + "Median Absolute Deviation" "Median 95% CI" + quantiles iqr + "25% and 75%-ile" "IQR" + range min + "Min - Max" "Minimum" + max median_range + "Maximum" "Median (Min - Max)" + cv geom_mean + "CV (%)" "Geometric Mean" + geom_mean_ci geom_cv + "Geometric Mean 95% CI" "CV % Geometric Mean" + +--- + + Code + res + Output + n count + "n" "count" + count_fraction n_blq + "count_fraction" "n_blq" + pval + "p-value (chi-squared test)" + +# summary_custom works as expected + + Code + res + Output + $stats + [1] "n" "sum" "mean" "sd" "se" + [6] "mean_sd" "mean_se" "mean_ci" "mean_sei" "mean_sdi" + [11] "mean_pval" "median" "mad" "median_ci" "quantiles" + [16] "iqr" "range" "min" "max" "median_range" + [21] "cv" "geom_mean" "geom_mean_ci" "geom_cv" + + $formats + n sum mean + "xx." "xx.x" "xx.x" + sd se mean_sd + "xx.x" "xx.x" "xx.x (xx.x)" + mean_se mean_ci mean_sei + "xx.x (xx.x)" "(xx.xx, xx.xx)" "(xx.xx, xx.xx)" + mean_sdi mean_pval median + "(xx.xx, xx.xx)" "xx.xx" "xx.x" + mad median_ci quantiles + "xx.x" "(xx.xx, xx.xx)" "xx.x - xx.x" + iqr range min + "xx.x" "xx.x - xx.x" "xx.x" + max median_range cv + "xx.x" "xx.x (xx.x - xx.x)" "xx.x" + geom_mean geom_mean_ci geom_cv + "xx.x" "(xx.xx, xx.xx)" "xx.x" + + $labels + n sum + "n" "Sum" + mean sd + "Mean" "SD" + se mean_sd + "SE" "Mean (SD)" + mean_se mean_ci + "Mean (SE)" "Mean 95% CI" + mean_sei mean_sdi + "Mean -/+ 1xSE" "Mean -/+ 1xSD" + mean_pval median + "Mean p-value (H0: mean = 0)" "Median" + mad median_ci + "Median Absolute Deviation" "Median 95% CI" + quantiles iqr + "25% and 75%-ile" "IQR" + range min + "Min - Max" "Minimum" + max median_range + "Maximum" "Median (Min - Max)" + cv geom_mean + "CV (%)" "Geometric Mean" + geom_mean_ci geom_cv + "Geometric Mean 95% CI" "CV % Geometric Mean" + + $indent_mods + n sum mean sd se mean_sd + 0 0 0 0 0 0 + mean_se mean_ci mean_sei mean_sdi mean_pval median + 0 0 0 0 0 0 + mad median_ci quantiles iqr range min + 0 0 0 0 0 0 + max median_range cv geom_mean geom_mean_ci geom_cv + 0 0 0 0 0 0 + + +--- + + Code + res + Output + $stats + [1] "n" "count" + + $formats + $formats$n + [1] "xx.xx" + + $formats$count + [1] "xx." + + + $labels + n count + "n" "#" + + $indent_mods + n count + 2 2 + + +# control_analyze_vars works with customized parameters + + Code + res + Output + $conf_level + [1] 0.9 + + $quantiles + [1] 0.1 0.9 + + $quantile_type + [1] 2 + + $test_mean + [1] 0 + + diff --git a/tests/testthat/test-analyze_variables.R b/tests/testthat/test-analyze_variables.R index 016d44c786..70d44f0914 100644 --- a/tests/testthat/test-analyze_variables.R +++ b/tests/testthat/test-analyze_variables.R @@ -1,51 +1,3 @@ -testthat::test_that("control_analyze_vars works with customized parameters", { - result <- control_analyze_vars( - conf_level = 0.9, - quantiles = c(0.1, 0.9) - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("control_analyze_vars fails wrong inputs", { - testthat::expect_error(control_analyze_vars(quantiles = c(25, 75))) - testthat::expect_error(control_analyze_vars(conf_level = 95)) -}) - -testthat::test_that("summary_formats works as expected", { - result <- summary_formats() - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - result <- summary_formats(type = "counts", include_pval = TRUE) - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("summary_labels works as expected", { - result <- summary_labels() - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - result <- summary_labels(type = "counts", include_pval = TRUE) - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("summary_custom works as expected", { - result <- summary_custom() - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - result <- summary_custom( - type = "counts", stats_custom = c("n", "count"), - formats_custom = c(n = "xx.xx"), labels_custom = c(count = "#"), indent_mods_custom = 2L - ) - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - testthat::test_that("s_summary return NA for x length 0L", { x <- numeric() diff --git a/tests/testthat/test-summary_stats.R b/tests/testthat/test-summary_stats.R new file mode 100644 index 0000000000..281de0be1f --- /dev/null +++ b/tests/testthat/test-summary_stats.R @@ -0,0 +1,47 @@ +testthat::test_that("summary_formats works as expected", { + result <- summary_formats() + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) + + result <- summary_formats(type = "counts", include_pval = TRUE) + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + +testthat::test_that("summary_labels works as expected", { + result <- summary_labels() + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) + + result <- summary_labels(type = "counts", include_pval = TRUE) + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + +testthat::test_that("summary_custom works as expected", { + result <- summary_custom() + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) + + result <- summary_custom( + type = "counts", stats_custom = c("n", "count"), + formats_custom = c(n = "xx.xx"), labels_custom = c(count = "#"), indent_mods_custom = 2L + ) + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + +testthat::test_that("control_analyze_vars works with customized parameters", { + result <- control_analyze_vars( + conf_level = 0.9, + quantiles = c(0.1, 0.9) + ) + + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + +testthat::test_that("control_analyze_vars fails wrong inputs", { + testthat::expect_error(control_analyze_vars(quantiles = c(25, 75))) + testthat::expect_error(control_analyze_vars(conf_level = 95)) +})