Skip to content

Commit

Permalink
more unit tests for ARD column names (#101)
Browse files Browse the repository at this point in the history
**What changes are proposed in this pull request?**


**Reference GitHub issue associated with pull request.** _e.g., 'closes
#1'_
#96 


--------------------------------------------------------------------------------

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] Ensure all package dependencies are installed:
`devtools::install_dev_deps()`
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and
review the rendered website.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`
- [ ] `usethis::use_spell_check()` runs with no spelling errors in
documentation

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cards (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] Increment the version number using `usethis::use_version(which =
"dev")`
- [ ] Run `usethis::use_spell_check()` again
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge".
  • Loading branch information
ddsjoberg authored Jan 4, 2024
1 parent 0847f7b commit 607c051
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/testthat/test-ard_categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,43 @@ test_that("ard_categorical() messaging", {
error = TRUE
)
})

test_that("ard_continuous() and ARD column names", {
ard_colnames <- c("group1", "group1_level", "variable", "variable_level",
"context", "stat_name", "stat_label", "statistic",
"statistic_fmt_fn", "warning", "error")

# no errors when these variables are the summary vars
expect_error({
lapply(
ard_colnames,
function(var) {
df <- mtcars[c("am", "mpg")]
names(df) <- c("am", var)
ard_categorical(
data = df,
by = "am",
variables = all_of(var)
)
}
)},
NA
)

# no errors when these vars are the by var
expect_error({
lapply(
ard_colnames,
function(byvar) {
df <- mtcars[c("am", "cyl")]
names(df) <- c(byvar, "cyl")
ard_continuous(
data = df,
by = all_of(byvar),
variables = "cyl"
)
}
)},
NA
)
})
34 changes: 34 additions & 0 deletions tests/testthat/test-ard_continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,40 @@ test_that("ard_continuous(stat_labels) argument works", {
dplyr::select(variable, stat_name, stat_label)

expect_equal(ard1, ard2)
})

test_that("ard_continuous() and ARD column names", {
ard_colnames <- c("group1", "group1_level", "variable", "variable_level",
"context", "stat_name", "stat_label", "statistic",
"statistic_fmt_fn", "warning", "error")

# no errors when these variables are the summary vars
expect_error({
df <- mtcars
names(df) <- ard_colnames
ard_continuous(
data = cbind(mtcars["am"], df),
variables = all_of(ard_colnames),
by = "am"
)},
NA
)

# no errors when these vars are the by var
expect_error({
lapply(
ard_colnames,
function(byvar) {
df <- mtcars[c("am", "mpg")]
names(df) <- c(byvar, "mpg")
ard_continuous(
data = df,
by = all_of(byvar),
variables = "mpg"
)
}
)},
NA
)
})

0 comments on commit 607c051

Please sign in to comment.