Skip to content

Commit

Permalink
Merge pull request #78 from r-lib/dont-show-tests
Browse files Browse the repository at this point in the history
Move table.integer64 tests from Rd to testthat suite
  • Loading branch information
MichaelChirico authored Oct 14, 2024
2 parents b6ab4c0 + 36a8ae4 commit c5e4f7c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
14 changes: 0 additions & 14 deletions R/highlevel64.R
Original file line number Diff line number Diff line change
Expand Up @@ -2022,20 +2022,6 @@ unipos.integer64 <- function(x
#'
#' message("via as.integer64.factor we can use 'table.integer64' also for factors")
#' table.integer64(x, as.integer64(as.factor(z)))
#'
#' \dontshow{
#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2))), table(c(1,1,2))))
#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
#' message("the following works with three warnings due to coercion")
#' stopifnot(identical(table.integer64(c(1,1,2)), table(c(1,1,2))))
#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4))))
#' stopifnot(identical(table.integer64(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
#' message("the following works because of ?")
#' stopifnot(identical(table(as.integer64(c(1,1,2))), table(c(1,1,2))))
#' stopifnot(identical(table(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
#' stopifnot(identical(table(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4))))
#' stopifnot(identical(table(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
#' }
#' @keywords category
#' @concept counts
#' @concept frequencies
Expand Down
14 changes: 0 additions & 14 deletions man/table.integer64.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions tests/testthat/test-highlevel64.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,41 @@ test_that("sorting methods work", {
expect_identical(quantile(x), q)
expect_identical(quantile(x, 0.2, names=FALSE), as.integer64(21L))
})

# These tests were previously kept as tests under \examples{\dontshow{...}}.
# Converted to "proper" unit tests for clarity, after making them more
# canonical within {testthat}, e.g. better capturing expected warnings,
# changing stopifnot(identical(...)) to expect_identical(...).
test_that("Old \\dontshow{} tests continue working", {
xi = c(1L, 1L, 2L)
xi64 = as.integer64(xi)
yi = c(3L, 4L, 4L)
yi64 = as.integer64(yi)

t_xi = table(x=xi)
t_xi_yi = table(x=xi, y=yi)

expect_identical(table.integer64(x=xi64), t_xi)
expect_identical(table.integer64(x=xi64, y=yi64), t_xi_yi)

expect_warning(
expect_identical(table.integer64(x=xi), t_xi),
"coercing first argument to integer64",
fixed = TRUE
)
expect_warning(
expect_identical(table.integer64(x=xi64, y=yi), t_xi_yi),
"coercing argument 2 to integer64",
fixed = TRUE
)
expect_warning(
expect_identical(table.integer64(x=xi, y=yi64), t_xi_yi),
"coercing argument 1 to integer64",
fixed = TRUE
)

expect_identical(table(x=xi64), t_xi)
expect_identical(table(x=xi64, y=yi64), t_xi_yi)
expect_identical(table(x=xi64, y=yi), t_xi_yi)
expect_identical(table(x=xi, y=yi64), t_xi_yi)
})

0 comments on commit c5e4f7c

Please sign in to comment.