Skip to content

Commit

Permalink
Fix integration tests, implement testthat 3rd edition (#59)
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
edelarua authored Dec 9, 2023
1 parent c5a377f commit a687fcd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/testthat/_snaps/tabulate_rbmi.md
Original file line number Diff line number Diff line change
@@ -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

24 changes: 1 addition & 23 deletions tests/testthat/test-tabulate_rbmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit a687fcd

Please sign in to comment.