Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More test coverage #51

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/highlevel64.R
Original file line number Diff line number Diff line change
Expand Up @@ -2999,11 +2999,13 @@ quantile.integer64 <- function(x, probs = seq(0.0, 1.0, 0.25), na.rm = FALSE, na
# TODO(R>=3.4.0): Drop this branch when median always gets '...'
# adding ... (wish of Kurt Hornik 23.3.2017)
if (is.na(match("...", names(formals(median))))){
# nocov start. Only run on old R.
median.integer64 <- function(x, na.rm=FALSE){
if (!na.rm && na.count(x)>0L)
stop("missing values not allowed with 'na.rm='==FALSE")
qtile.integer64(x, probs = 0.5, na.rm = na.rm, names = FALSE)
}
# nocov end.
}else{
median.integer64 <- function(x, na.rm=FALSE, ...){
if (!na.rm && na.count(x)>0L)
Expand Down
47 changes: 46 additions & 1 deletion tests/testthat/test-highlevel64.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("match basics work", {
test_that("match & %in% basics work", {
x = as.integer64(2:5)
y = as.integer64(3:6)
expect_identical(match(x, y), c(NA, 1:3))
Expand All @@ -10,4 +10,49 @@ test_that("match basics work", {
expect_identical(match(y, as.numeric(2:5)), c(2:4, NA))

expect_identical(match(x, y, nomatch=0L), 0:3)

expect_identical(x %in% y, c(FALSE, TRUE, TRUE, TRUE))
expect_identical(y %in% x, c(TRUE, TRUE, TRUE, FALSE))
expect_identical(x %in% 3:6, c(FALSE, TRUE, TRUE, TRUE))
expect_identical(x %in% c(3.0, 4.0, 5.0, 6.0), c(FALSE, TRUE, TRUE, TRUE))
})

test_that("duplicated, unique, table methods work", {
x = as.integer64(1:3)
expect_identical(duplicated(x), rep(FALSE, 3L))
expect_identical(unique(x), x)
expect_identical(table(x), table(x = 1:3))

x = as.integer64(rep(1L, 3L))
expect_identical(duplicated(x), c(FALSE, TRUE, TRUE))
expect_identical(unique(x), x[1L])
expect_identical(table(x), table(x = rep(1L, 3L)))

x = as.integer64(c(1L, 2L, 1L))
expect_identical(duplicated(x), c(FALSE, FALSE, TRUE))
expect_identical(unique(x), x[1:2])
expect_identical(table(x), table(x = c(1L, 2L, 1L)))

x = as.integer64(c(1L, 1L, 2L))
expect_identical(duplicated(x), c(FALSE, TRUE, FALSE))
expect_identical(unique(x), x[c(1L, 3L)])
expect_identical(table(x), table(x = c(1L, 1L, 2L)))
})

test_that("more coercion works", {
expect_identical(as.factor(as.integer64(2:4)), factor(2:4))
expect_identical(as.ordered(as.integer64(2:4)), as.ordered(2:4))
expect_identical(as.integer64(factor(2:11)), as.integer64(1:10)) # NB: _not_ 2:11!
})

test_that("sorting methods work", {
expect_identical(rank(as.integer64(c(10L, 4L, 8L))), c(3.0, 1.0, 2.0))

x = as.integer64(1:100)
q = as.integer64(c(1L, 26L, 50L, 75L, 100L))
expect_identical(quantile(x, names=FALSE), q)
expect_identical(median(x), q[3L])
names(q) = c('0%', '25%', '50%', '75%', '100%')
expect_identical(quantile(x), q)
expect_identical(quantile(x, 0.2, names=FALSE), as.integer64(21L))
})
1 change: 0 additions & 1 deletion tests/testthat/test-integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ test_that("integer64 coercion to/from other types work", {
# to integer64
expect_identical(as.integer64(TRUE), as.integer64(1L))
expect_identical(as.integer64(as.character(1:10)), as.integer64(1:10))
expect_identical(as.integer64(factor(2:11)), as.integer64(1:10)) # NB: _not_ 2:11!
expect_identical(as.integer64(as.double(1:10)), as.integer64(1:10))
expect_identical(as.integer64(NULL), as.integer64())
x = as.integer64(1:10)
Expand Down
Loading