Skip to content

Commit

Permalink
more basic coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Oct 9, 2024
1 parent 18d094c commit 64b837c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ function (..., recursive = FALSE)
K <- length(l)
for (k in 1:K){
if (recursive && is.list(l[[k]])){
l[[k]] <- do.call("c.integer64", c(l[[k]], list(recursive = TRUE)))
l[[k]] <- do.call(c.integer64, c(l[[k]], list(recursive = TRUE)))

Check warning on line 2254 in R/integer64.R

View check run for this annotation

Codecov / codecov/patch

R/integer64.R#L2254

Added line #L2254 was not covered by tests
}else{
if (!is.integer64(l[[k]])) {
nam <- names(l[[k]])
Expand All @@ -2261,7 +2261,7 @@ function (..., recursive = FALSE)
oldClass(l[[k]]) <- NULL
}
}
ret <- do.call("c", l)
ret <- do.call(c, l)
oldClass(ret) <- "integer64"
ret
}
Expand All @@ -2278,7 +2278,7 @@ cbind.integer64 <- function(...){
}
oldClass(l[[k]]) <- NULL
}
ret <- do.call("cbind", l)
ret <- do.call(cbind, l)
oldClass(ret) <- "integer64"
ret
}
Expand All @@ -2294,7 +2294,7 @@ rbind.integer64 <- function(...){
}
oldClass(l[[k]]) <- NULL
}
ret <- do.call("rbind", l)
ret <- do.call(rbind, l)
oldClass(ret) <- "integer64"
ret
}
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
packageStartupMessage("WARNING semantics differ from integer")
packageStartupMessage("for more help type ?bit64")
}

# nocov start
.onUnload <- function(libpath){
packageStartupMessage("Unloading package bit64")
library.dynam.unload("bit64", libpath)
}
# nocov end
22 changes: 22 additions & 0 deletions tests/testthat/test-integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ test_that("indexing works", {

expect_identical(x[3L], as.integer64(3L))
expect_identical(x[[4L]], as.integer64(4L))

names(x) = letters[1:10]
expect_identical(x[c("b", "c")], x[2:3])
expect_identical(x[["d"]], x[[4L]])
})

test_that("arithmetic & basic math works", {
Expand All @@ -64,6 +68,7 @@ test_that("arithmetic & basic math works", {
# output is double even though it fits in integer [and integer64]
expect_identical(x[seq(2L, 10L, by=2L)] / 2L, as.double(1:5))
expect_identical(x ^ 2L, as.integer64((1:10)^2L))
expect_identical(-x, as.integer64(-(1:10)))

expect_identical(x %/% 2L, as.integer64(c(0L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L)))
expect_identical(x %% 2L, as.integer64(rep_len(c(1L, 0L), 10L)))
Expand All @@ -85,18 +90,35 @@ test_that("arithmetic & basic math works", {
expect_identical(round(x), x)

expect_identical(round(x, -1L), as.integer64(rep(c(0L, 10L), each=5L)))
})

test_that("basic statistics work", {
x = as.integer64(1:10)

expect_identical(sum(x), as.integer64(55L))
expect_identical(sum(x, x), as.integer64(110L))
expect_identical(prod(x), as.integer64(factorial(10L)))
expect_identical(prod(x[1:5], x[6:10]), as.integer64(factorial(10L)))
expect_identical(min(x), x[1L])
expect_identical(min(x, as.integer64(0L)), as.integer64(0L))
expect_identical(max(x), x[10L])
expect_identical(max(x, as.integer64(11L)), as.integer64(11L))
expect_identical(range(x), x[c(1L, 10L)])
expect_identical(range(x, x+1L), c(x[1L], x[10L]+1L))

expect_identical(diff(x), as.integer64(rep(1L, 9L)))

expect_identical(cummin(x), as.integer64(rep(1L, 10L)))
expect_identical(cummax(x), x)
expect_identical(cumsum(x), as.integer64(choose(2:11, 2L)))
expect_identical(cumprod(x), as.integer64(factorial(1:10)))
})

test_that("display methods work", {
x = as.integer64(1:3)
expect_identical(format(x), as.character(1:3))
expect_output(print(x), "integer64.*\\s*1\\s*2\\s*3")
expect_output(print(x[0L]), "integer64(0)", fixed=TRUE)
expect_output(str(x), "integer64 [1:3] 1 2 3", fixed=TRUE)
})

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-patch64.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("base generic overwrites work", {
x = c(2L, 4L, 3L)
expect_identical(rank(x), c(1.0, 3.0, 2.0))
expect_identical(order(x), c(1L, 3L, 2L))
})
3 changes: 3 additions & 0 deletions tests/testthat/test-sort64.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("order basics work", {
expect_identical(order(as.integer64(c(2L, 4L, 3L))), c(1L, 3L, 2L))
})

0 comments on commit 64b837c

Please sign in to comment.