From a407f29030f7913bc33523b22c5b05a012af17e6 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Fri, 8 Dec 2023 18:20:34 -0500 Subject: [PATCH] Fix integration tests, implement testthat 3e --- DESCRIPTION | 7 ++--- tests/testthat/_snaps/tabulate_rbmi.md | 36 ++++++++++++++++++++++++++ tests/testthat/test-tabulate_rbmi.R | 24 +---------------- 3 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 tests/testthat/_snaps/tabulate_rbmi.md diff --git a/DESCRIPTION b/DESCRIPTION index f91e223..089b5f9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,14 +15,14 @@ BugReports: https://github.com/insightsengineering/tern.rbmi/issues Depends: R (>= 3.6), rbmi (>= 1.2.5), - tern (>= 0.7.10) + tern (>= 0.9.3) Imports: broom (>= 0.5.4), checkmate (>= 2.1.0), - formatters (>= 0.3.1), + formatters (>= 0.5.5), lifecycle (>= 0.2.0), magrittr (>= 1.5), - rtables (>= 0.5.1) + rtables (>= 0.6.6) Suggests: dplyr (>= 1.0.3), knitr (>= 1.42), @@ -40,6 +40,7 @@ Config/Needs/verdepcheck: insightsengineering/rbmi, insightsengineering/rtables, tidyverse/dplyr, yihui/knitr, rstudio/rmarkdown, r-lib/testthat, tidyverse/tidyr Config/Needs/website: insightsengineering/nesttemplate +Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US LazyData: true diff --git a/tests/testthat/_snaps/tabulate_rbmi.md b/tests/testthat/_snaps/tabulate_rbmi.md new file mode 100644 index 0000000..7bad0df --- /dev/null +++ b/tests/testthat/_snaps/tabulate_rbmi.md @@ -0,0 +1,36 @@ +# summarize_rbmi works as expected with valid input + + Code + result + Output + Visit ref alt + ————————————————————————————————————————————————————————————————————————— + 4 + Adjusted Mean (SE) -1.616 (0.486) -1.708 (0.475) + 95% CI (-2.576, -0.656) (-2.645, -0.770) + Difference in Adjusted Means (SE) -0.092 (0.683) + 95% CI (-1.439, 1.256) + Relative Reduction (%) 5.7% + p-value (RBMI) 0.8932 + 5 + Adjusted Mean (SE) -4.225 (0.656) -2.874 (0.648) + 95% CI (-5.520, -2.930) (-4.154, -1.593) + Difference in Adjusted Means (SE) 1.351 (0.922) + 95% CI (-0.470, 3.172) + Relative Reduction (%) -32.0% + p-value (RBMI) 0.1447 + 6 + Adjusted Mean (SE) -6.381 (0.703) -4.159 (0.696) + 95% CI (-7.771, -4.991) (-5.536, -2.782) + Difference in Adjusted Means (SE) 2.222 (0.975) + 95% CI (0.296, 4.149) + Relative Reduction (%) -34.8% + p-value (RBMI) 0.0241 + 7 + Adjusted Mean (SE) -7.580 (0.791) -4.760 (0.756) + 95% CI (-9.145, -6.016) (-6.254, -3.267) + Difference in Adjusted Means (SE) 2.820 (1.085) + 95% CI (0.676, 4.964) + Relative Reduction (%) -37.2% + p-value (RBMI) 0.0103 + diff --git a/tests/testthat/test-tabulate_rbmi.R b/tests/testthat/test-tabulate_rbmi.R index c1f3a8b..c898413 100644 --- a/tests/testthat/test-tabulate_rbmi.R +++ b/tests/testthat/test-tabulate_rbmi.R @@ -77,27 +77,5 @@ testthat::test_that("summarize_rbmi works as expected with valid input", { summarize_rbmi() %>% build_table(df) - result_matrix <- to_string_matrix(result) - expected_matrix <- structure( - matrix( - nrow = 29, - ncol = 3, - data = c( - "Visit", "4", "Adjusted Mean (SE)", "95% CI", "Difference in Adjusted Means (SE)", "95% CI", - "Relative Reduction (%)", "p-value (RBMI)", "5", "Adjusted Mean (SE)", "95% CI", - "Difference in Adjusted Means (SE)", "95% CI", "Relative Reduction (%)", "p-value (RBMI)", - "6", "Adjusted Mean (SE)", "95% CI", "Difference in Adjusted Means (SE)", "95% CI", - "Relative Reduction (%)", "p-value (RBMI)", "7", "Adjusted Mean (SE)", "95% CI", - "Difference in Adjusted Means (SE)", "95% CI", "Relative Reduction (%)", "p-value (RBMI)", - "ref", "", "-1.616 (0.486)", "(-2.576, -0.656)", "", "", "", "", "", "-4.225 (0.656)", - "(-5.520, -2.930)", "", "", "", "", "", "-6.381 (0.703)", "(-7.771, -4.991)", "", "", "", "", - "", "-7.580 (0.791)", "(-9.145, -6.016)", "", "", "", "", "alt", "", "-1.708 (0.475)", "(-2.645, -0.770)", - "-0.092 (0.683)", "(-1.439, 1.256)", "5.7%", "0.8932", "", "-2.874 (0.648)", "(-4.154, -1.593)", - "1.351 (0.922)", "(-0.470, 3.172)", "-32.0%", "0.1447", "", "-4.159 (0.696)", "(-5.536, -2.782)", - "2.222 (0.975)", "(0.296, 4.149)", "-34.8%", "0.0241", "", "-4.760 (0.756)", "(-6.254, -3.267)", - "2.820 (1.085)", "(0.676, 4.964)", "-37.2%", "0.0103" - ) - ) - ) - testthat::expect_identical(result_matrix, expected_matrix) + testthat::expect_snapshot(result) })