diff --git a/R/highlevel64.R b/R/highlevel64.R index 6096b71..319d087 100644 --- a/R/highlevel64.R +++ b/R/highlevel64.R @@ -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) diff --git a/tests/testthat/test-highlevel64.R b/tests/testthat/test-highlevel64.R index 286e971..f4b8739 100644 --- a/tests/testthat/test-highlevel64.R +++ b/tests/testthat/test-highlevel64.R @@ -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)) @@ -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)) }) diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index 4b00e63..bd6572b 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -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)