Unit tests
unit-tests.Rmd
Unit tests
The unit tests have been removed from msst2ap
to focus
on the shinytest2
tests, but I’ve stored each each of them
are stored the tests for each R file in this vignette for
completeness.
find_vars()
Test function (is.double
)
testthat::test_that("find_vars", {
testthat::expect_equal(
object = find_vars(datasets::airquality,
filter = is.double),
expected = names(airquality)[vapply(airquality, is.double, logical(1))])
test_cmt("find_vars", "is.double()")
})
#>
#> find_vars: is.double()
#> Test passed
Test function (is.character
)
testthat::test_that("find_vars", {
testthat::expect_equal(
object = find_vars(datasets::mtcars,
filter = is.character),
expected = datasets::mtcars |>
dplyr::select(where(is.character)) |>
names())
test_cmt("find_vars", "is.character()")
})
#>
#> find_vars: is.character()
#> Test passed
Test error: state.abb
is a vector–pass
is.character
function to filter
find_vars(data = datasets::state.abb, is.character)
#> Error in find_vars(data = datasets::state.abb, is.character): is.data.frame(data) is not TRUE
testthat::test_that("find_vars", {
testthat::expect_error(object =
find_vars(datasets::state.abb, filter = is.character))
test_cmt("find_vars", "error: data")
})
#>
#> find_vars: error: data
#> Test passed
Test error: pass is.miracle
function to
filter
find_vars(data = datasets::mtcars, is.miracle)
#> Error in eval(expr, envir, enclos): object 'is.miracle' not found
testthat::test_that("find_vars", {
testthat::expect_error(object =
find_vars(datasets::mtcars, filter = is.miracle))
test_cmt("find_vars", "error: filter")
})
#>
#> find_vars: error: filter
#> Test passed