Skip to content

Commit

Permalink
docs: add news and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Nov 10, 2023
1 parent bfa4594 commit cf0cc59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Filter state snapshots can now be uploaded from file. See `?snapshot`.
* Added argument to `teal_slices` and made modifications to `init` to enable tagging `teal_slices` with an app id to safely upload snapshots from disk.
* Added `landing_popup_module` function which creates a module that will display a popup when the app starts. The popup will block access to the app until it is dismissed.
* `validate_has_data` now accepts a `vector` input along with `data.frame`.

# teal 0.14.0

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-validate_has_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,73 @@ data <- data.frame(x = 1:10, y = c(1:9, NA), z = c(Inf, 2:10))
testthat::test_that("validate_has_data throws no error when data has at least as many rows as min_nrow", {
testthat::expect_silent(validate_has_data(data, 10))
testthat::expect_silent(validate_has_data(data, 5))
testthat::expect_silent(validate_has_data(data$x, 10))
testthat::expect_silent(validate_has_data(data$x, 5))
})

testthat::test_that("validate_has_data throws error when min_nrow > #rows of data", {
testthat::expect_error(validate_has_data(data, 11))
testthat::expect_error(validate_has_data(data$x, 11))
})

testthat::test_that("validate_has_data accepts logical complete argument", {
testthat::expect_silent(validate_has_data(data[, c("x", "z")], 10, complete = TRUE))
testthat::expect_silent(validate_has_data(data[, c("x", "z")], 10, complete = FALSE))
testthat::expect_silent(validate_has_data(data$x, 10, complete = TRUE))
testthat::expect_silent(validate_has_data(data$x, 10, complete = FALSE))
})

testthat::test_that("validate_has_data throws error when data has NA and complete is set to TRUE", {
testthat::expect_error(validate_has_data(data[, c("x", "y")], 10, complete = TRUE))
testthat::expect_error(validate_has_data(data$y, 10, complete = TRUE))
})

testthat::test_that("validate_has_data accepts logical allow_inf argument", {
testthat::expect_silent(validate_has_data(data[, c("x", "y")], 10, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data[, c("x", "y")], 10, complete = TRUE, allow_inf = FALSE))
testthat::expect_silent(validate_has_data(data$y, 10, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data$y, 10, complete = TRUE, allow_inf = FALSE))
})

testthat::test_that("validate_has_data accepts throws error when data has Inf values and allow_inf is set to FALSE", {
testthat::expect_error(validate_has_data(data[, c("x", "z")], 10, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data$z, 10, allow_inf = FALSE))
})

testthat::test_that("validate_has_data accepts throws error when data has Inf values and allow_inf is set to FALSE", {
testthat::expect_error(validate_has_data(data[, c("x", "z")], 10, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data[, c("x", "z")], 10, complete = TRUE, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data$z, 10, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data$z, 10, complete = TRUE, allow_inf = FALSE))
})

testthat::test_that("validate_has_data allow_inf argument ignores non-numeric columns", {
data <- data.frame(x = 3:5, w = c("A", "B", "C"), z = c(Inf, 4, 5))
testthat::expect_silent(validate_has_data(data[, c("x", "w")], 3, allow_inf = FALSE))
testthat::expect_error(validate_has_data(data, 3, allow_inf = FALSE))
testthat::expect_silent(validate_has_data(data$w, 3, allow_inf = FALSE))
})

testthat::test_that("validate_has_data returns message when msg argument is set", {
testthat::expect_error(
validate_has_data(data, 11, msg = "Check data."),
"Minimum number of records not met: >= 11 records required.\nCheck data."
)
testthat::expect_error(
validate_has_data(data$x, 11, msg = "Check data."),
"Minimum number of records not met: >= 11 records required.\nCheck data."
)
})

testthat::test_that("validate_has_data returns message msg argument is set and complete is set to TRUE", {
testthat::expect_error(
validate_has_data(data[, c("x", "y")], 11, complete = TRUE, msg = "Check data."),
"Number of complete cases is less than: 11\nCheck data."
)
testthat::expect_error(
validate_has_data(data$y, 11, complete = TRUE, msg = "Check data."),
"Number of complete cases is less than: 11\nCheck data."
)
})

testthat::test_that("validate_has_data returns throws error with non-character msg input", {
Expand Down

0 comments on commit cf0cc59

Please sign in to comment.