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

Move remaining \dontshow implicit unit tests into explicit tests/ #80

Merged
merged 5 commits into from
Oct 15, 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
202 changes: 0 additions & 202 deletions R/bit64-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,208 +486,6 @@
#' load(file=fi64)
#' identical.integer64(d,e)
#'
#' ### A couple of unit tests follow hidden in a dontshow{} directive ###
#' \dontshow{
#' message("Testing identical.integer64")
#' i64 <- as.double(NA); class(i64) <- "integer64"
#' stopifnot(identical(unclass(i64-1), unclass(i64+1)))
#' stopifnot(identical(i64-1, i64+1))
#' stopifnot(!identical.integer64(i64-1, i64+1))
#'
#' message("Testing dispatch of 'c' method")
#' stopifnot(identical.integer64(c(integer64(0), NA), as.integer64(NA)))
#' message("Dispatch on the second argument fails and we want to be notified once that changes")
#' stopifnot(!identical.integer64(c(NA, integer64(0)), as.integer64(NA)))
#'
#' message("Testing minus and plus")
#' d64 <- c(-.Machine$double.base^.Machine$double.digits, -.Machine$integer.max, -1, 0, 1, .Machine$integer.max, .Machine$double.base^.Machine$double.digits)
#' i64 <- as.integer64(d64)
#' stopifnot(identical.integer64(i64-1+1,i64))
#' stopifnot(identical.integer64(i64+1-1,i64))
#'
#' message("Testing minus and plus edge cases and 'rev'\nUBSAN signed integer overflow expected for type 'long long int'\nThis is a false UBSAN alarm because overflow is detected and NA returned")
#' stopifnot(identical.integer64(lim.integer64()+1-1, c(lim.integer64()[1], NA)))
#' stopifnot(identical.integer64(rev(lim.integer64())-1+1, c(lim.integer64()[2], NA)))
#'
#' message("Testing 'range.integer64', multiplication and integer division")
#' i64 <- integer64(63)
#' i64[1] <- 1
#' for (i in 2:63)
#' i64[i] <- 2*i64[i-1]
#' stopifnot(identical.integer64(i64 * rev(i64), rep(i64[63], 63)))
#' for (i in 63:2)
#' i64[i-1] <- i64[i]%/%2
#' stopifnot(identical.integer64(i64 * rev(i64), rep(i64[63], 63)))
#' for (i in 63:2)
#' i64[i-1] <- i64[i]/2
#' stopifnot(identical.integer64(i64 * rev(i64), rep(i64[63], 63)))
#' stopifnot(identical.integer64(c( -i64[63] - (i64[63]-1), i64[63]+(i64[63]-1) ), lim.integer64()))
#'
#' stopifnot(identical.integer64(i64[-1]%/%2*as.integer64(2), i64[-1]))
#' stopifnot(identical.integer64(i64[-1]%/%2L*as.integer64(2), i64[-1]))
#' stopifnot(identical.integer64(i64[-1]/2*as.integer64(2), i64[-1]))
#' stopifnot(identical.integer64(i64[-1]/2*as.integer64(2), i64[-1]))
#'
#' stopifnot(identical.integer64(i64[-63]*2%/%2, i64[-63]))
#' stopifnot(identical.integer64(i64[-63]*2L%/%2L, i64[-63]))
#' stopifnot(identical.integer64(as.integer64(i64[-63]*2/2), i64[-63]))
#' stopifnot(identical.integer64(as.integer64(i64[-63]*2L/2L), i64[-63]))
#'
#' message("Testing sqrt, power and log")
#' stopifnot(identical.integer64( as.integer64(sqrt(i64[-1][c(FALSE, TRUE)])*sqrt(i64[-1][c(FALSE, TRUE)])), i64[-1][c(FALSE, TRUE)] ))
#'
#' stopifnot(identical.integer64(as.integer64(2)^(0:62), i64))
#' stopifnot(identical.integer64(as.integer64(0:62), as.integer64(round(log2(i64)))))
#' stopifnot(identical.integer64(as.integer64(round(log(as.integer64(2)^(0:62), 2))), as.integer64(0:62)))
#' stopifnot(identical.integer64(as.integer64(round(log(as.integer64(3)^(0:39), 3))), as.integer64(0:39)))
#' stopifnot(identical.integer64(as.integer64(round(log(as.integer64(10)^(0:18), 10))), as.integer64(0:18)))
#' stopifnot(identical.integer64(as.integer64(round(log10(as.integer64(10)^(0:18)))), as.integer64(0:18)))
#'
#' stopifnot(identical.integer64((as.integer64(2)^(1:62))^(1/1:62), as.integer64(rep(2, 62))))
#' stopifnot(identical.integer64((as.integer64(3)^(1:39))^(1/1:39), as.integer64(rep(3, 39))))
#' stopifnot(identical.integer64((as.integer64(10)^(1:18))^(1/1:18), as.integer64(rep(10, 18))))
#'
#' message("Testing c and rep")
#' stopifnot(identical.integer64( as.integer64(rep(1:3, 1:3)), rep(as.integer64(1:3), 1:3)))
#' stopifnot(identical.integer64( as.integer64(rep(1:3, 3)), rep(as.integer64(1:3), 3)))
#'
#' x <- as.double(c(NA,NA,NA))
#' class(x) <- "integer64"
#' x <- x + -1:1
#' stopifnot(identical.integer64(rep(x, 3), c(x,x,x) ))
#' stopifnot(identical.integer64(c.integer64(list(x,x,x), recursive=TRUE), c(x,x,x) ))
#'
#' message("Testing seq")
#' stopifnot(identical.integer64(seq(as.integer64(1), 10, 2), as.integer64(seq(1, 10, 2)) ))
#' stopifnot(identical.integer64(seq(as.integer64(1), by=2, length.out=5), as.integer64(seq(1, by=2, length.out=5)) ))
#' stopifnot(identical.integer64(seq(as.integer64(1), by=2, length.out=6), as.integer64(seq(1, by=2, length.out=6)) ))
#' stopifnot(identical.integer64(seq.integer64(along.with=3:5), as.integer64(seq(along.with=3:5)) ))
#' stopifnot(identical.integer64(seq(as.integer64(1), to=-9), as.integer64(seq(1, to=-9)) ))
#'
#' message("Testing cbind and rbind")
#' stopifnot(identical.integer64( cbind(as.integer64(1:3), 1:3), {x <- rep(as.integer64(1:3), 2); dim(x)<-c(3,2);x}))
#' stopifnot(identical.integer64( rbind(as.integer64(1:3), 1:3), t({x <- rep(as.integer64(1:3), 2); dim(x)<-c(3,2);x})))
#'
#' message("Testing coercion")
#' stopifnot(identical( as.double(as.integer64(c(NA, seq(0, 9, 0.25)))), as.double(as.integer(c(NA, seq(0, 9, 0.25))))))
#' stopifnot(identical( as.character(as.integer64(c(NA, seq(0, 9, 0.25)))), as.character(as.integer(c(NA, seq(0, 9, 0.25))))))
#' stopifnot(identical( as.integer(as.integer64(c(NA, seq(0, 9, 0.25)))), as.integer(c(NA, seq(0, 9, 0.25)))))
#' stopifnot(identical( as.logical(as.integer64(c(NA, seq(0, 9, 0.25)))), as.logical(as.integer(c(NA, seq(0, 9, 0.25))))))
#' stopifnot(identical( as.integer(as.integer64(c(NA, FALSE, TRUE))), as.integer(c(NA, FALSE, TRUE))))
#' stopifnot(identical( as.integer64(as.integer(as.integer64(-9:9))), as.integer64(-9:9)))
#' stopifnot(identical( as.integer64(as.double(as.integer64(-9:9))), as.integer64(-9:9)))
#' stopifnot(identical( as.integer64(as.character(as.integer64(-9:9))), as.integer64(-9:9)))
#' stopifnot(identical( as.integer64(as.character(lim.integer64())), lim.integer64()))
#'
#' message("-- testing logical operators --")
#' stopifnot(identical.integer64(!c(NA, -1:1), !c(as.integer64(NA), -1:1)))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)&rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))&as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)|rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))|as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(xor(rep(c(NA, -1:1), 4),rep(c(NA, -1:1), rep(4, 4))), xor(as.integer64(rep(c(NA, -1:1), 4)),as.integer64(rep(c(NA, -1:1), rep(4, 4))))))
#'
#' message("-- testing comparison operators --")
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)==rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))==as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)!=rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))!=as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)>rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))>as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)>=rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))>=as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)<rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))<as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#' stopifnot(identical.integer64(rep(c(NA, -1:1), 4)<=rep(c(NA, -1:1), rep(4, 4)), as.integer64(rep(c(NA, -1:1), 4))<=as.integer64(rep(c(NA, -1:1), rep(4, 4)))))
#'
#' message("-- testing vector functions --")
#' stopifnot(identical.integer64( is.na(as.integer64(c(NA, -1:1))), is.na(c(NA, -1:1)) ))
#' stopifnot(identical.integer64( format(as.integer64(c(NA, -1:1))), format(c(NA, -1:1)) ))
#' stopifnot(identical.integer64( abs(as.integer64(c(NA, -1:1))), as.integer64(abs(c(NA, -1:1))) ))
#' stopifnot(identical.integer64( sign(as.integer64(c(NA, -1:1))), as.integer64(sign(c(NA, -1:1))) ))
#' stopifnot(identical.integer64( ceiling(as.integer64(c(NA, -1:1))), as.integer64(ceiling(c(NA, -1:1))) ))
#' stopifnot(identical.integer64( floor(as.integer64(c(NA, -1:1))), as.integer64(floor(c(NA, -1:1))) ))
#' stopifnot(identical.integer64( trunc(as.integer64(c(NA, -1:1))), as.integer64(trunc(c(NA, -1:1))) ))
#' stopifnot(identical.integer64( signif(as.integer64(c(NA, -1:1))), as.integer64(c(NA, -1:1)) ))
#'
#' message("Testing summary functions")
#' stopifnot(identical(all(as.integer(1)), all(as.integer64(1))))
#' stopifnot(identical(all(as.integer(0)), all(as.integer64(0))))
#' stopifnot(identical(all(as.integer(NA)), all(as.integer64(NA))))
#' stopifnot(identical(all(as.integer(NA), na.rm=TRUE), all(as.integer64(NA), na.rm=TRUE)))
#' stopifnot(identical(all(as.integer(1), NA), all(as.integer64(1), NA)))
#' stopifnot(identical(all(as.integer(0), NA), all(as.integer64(0), NA)))
#' stopifnot(identical(all(as.integer(1), NA, na.rm=TRUE), all(as.integer64(1), NA, na.rm=TRUE)))
#' stopifnot(identical(all(as.integer(0), NA, na.rm=TRUE), all(as.integer64(0), NA, na.rm=TRUE)))
#' stopifnot(identical(all(as.integer(c(1, NA))), all(as.integer64(c(1, NA)))))
#' stopifnot(identical(all(as.integer(c(0, NA))), all(as.integer64(c(0, NA)))))
#' stopifnot(identical(all(as.integer(c(1, NA)), na.rm=TRUE), all(as.integer64(c(1, NA)), na.rm=TRUE)))
#' stopifnot(identical(all(as.integer(c(0, NA)), na.rm=TRUE), all(as.integer64(c(0, NA)), na.rm=TRUE)))
#'
#' stopifnot(identical(any(as.integer(1)), any(as.integer64(1))))
#' stopifnot(identical(any(as.integer(0)), any(as.integer64(0))))
#' stopifnot(identical(any(as.integer(NA)), any(as.integer64(NA))))
#' stopifnot(identical(any(as.integer(NA), na.rm=TRUE), any(as.integer64(NA), na.rm=TRUE)))
#' stopifnot(identical(any(as.integer(1), NA), any(as.integer64(1), NA)))
#' stopifnot(identical(any(as.integer(0), NA), any(as.integer64(0), NA)))
#' stopifnot(identical(any(as.integer(1), NA, na.rm=TRUE), any(as.integer64(1), NA, na.rm=TRUE)))
#' stopifnot(identical(any(as.integer(0), NA, na.rm=TRUE), any(as.integer64(0), NA, na.rm=TRUE)))
#' stopifnot(identical(any(as.integer(c(1, NA))), any(as.integer64(c(1, NA)))))
#' stopifnot(identical(any(as.integer(c(0, NA))), any(as.integer64(c(0, NA)))))
#' stopifnot(identical(any(as.integer(c(1, NA)), na.rm=TRUE), any(as.integer64(c(1, NA)), na.rm=TRUE)))
#' stopifnot(identical(any(as.integer(c(0, NA)), na.rm=TRUE), any(as.integer64(c(0, NA)), na.rm=TRUE)))
#'
#' stopifnot(identical.integer64(as.integer64(sum(c(2, 3, NA))), sum(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(sum(c(2, 3, NA), na.rm=TRUE)), sum(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(sum(c(2, 3, NA))), sum(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(sum(c(2, 3, NA), na.rm=TRUE)), sum(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(sum(2, 3, NA)), sum(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(sum(2, 3, NA, na.rm=TRUE)), sum(as.integer64(2), 3, NA, na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(sum(2, 3, NA)), sum(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(sum(2, 3, NA, na.rm=TRUE)), sum(as.integer64(2), 3, NA, na.rm=TRUE)))
#'
#' stopifnot(identical.integer64(as.integer64(prod(c(2, 3, NA))), prod(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(prod(c(2, 3, NA), na.rm=TRUE)), prod(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(prod(c(2, 3, NA))), prod(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(prod(c(2, 3, NA), na.rm=TRUE)), prod(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(prod(2, 3, NA)), prod(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(prod(2, 3, NA, na.rm=TRUE)), prod(as.integer64(2), 3, NA, na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(prod(2, 3, NA)), prod(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(prod(2, 3, NA, na.rm=TRUE)), prod(as.integer64(2), 3, NA, na.rm=TRUE)))
#'
#' stopifnot(identical.integer64(as.integer64(min(c(2, 3, NA))), min(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(min(c(2, 3, NA), na.rm=TRUE)), min(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(min(c(2, 3, NA))), min(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(min(c(2, 3, NA), na.rm=TRUE)), min(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(min(2, 3, NA)), min(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(min(2, 3, NA, na.rm=TRUE)), min(as.integer64(2), 3, NA, na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(min(2, 3, NA)), min(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(min(2, 3, NA, na.rm=TRUE)), min(as.integer64(2), 3, NA, na.rm=TRUE)))
#'
#' stopifnot(identical.integer64(as.integer64(max(c(2, 3, NA))), max(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(max(c(2, 3, NA), na.rm=TRUE)), max(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(max(c(2, 3, NA))), max(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(max(c(2, 3, NA), na.rm=TRUE)), max(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(max(2, 3, NA)), max(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(max(2, 3, NA, na.rm=TRUE)), max(as.integer64(2), 3, NA, na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(max(2, 3, NA)), max(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(max(2, 3, NA, na.rm=TRUE)), max(as.integer64(2), 3, NA, na.rm=TRUE)))
#'
#' stopifnot(identical.integer64(as.integer64(range(c(2, 3, NA))), range(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(range(c(2, 3, NA), na.rm=TRUE)), range(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(range(c(2, 3, NA))), range(as.integer64(c(2, 3, NA)))))
#' stopifnot(identical.integer64(as.integer64(range(c(2, 3, NA), na.rm=TRUE)), range(as.integer64(c(2, 3, NA)), na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(range(2, 3, NA)), range(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(range(2, 3, NA, na.rm=TRUE)), range(as.integer64(2), 3, NA, na.rm=TRUE)))
#' stopifnot(identical.integer64(as.integer64(range(2, 3, NA)), range(as.integer64(2), 3, NA)))
#' stopifnot(identical.integer64(as.integer64(range(2, 3, NA, na.rm=TRUE)), range(as.integer64(2), 3, NA, na.rm=TRUE)))
#'
#' message("-- testing cummulative functions --")
#' stopifnot(identical.integer64(as.integer64(cumsum(c(2, 3, NA, 1, 4))), cumsum(as.integer64(c(2, 3, NA, 1, 4)))))
#' stopifnot(identical.integer64(as.integer64(cumprod(c(2, 3, NA, 1, 4))), cumprod(as.integer64(c(2, 3, NA, 1, 4)))))
#' stopifnot(identical.integer64(as.integer64(cummin(c(2, 3, NA, 1, 4))), cummin(as.integer64(c(2, 3, NA, 1, 4)))))
#' stopifnot(identical.integer64(as.integer64(cummax(c(2, 3, NA, 1, 4))), cummax(as.integer64(c(2, 3, NA, 1, 4)))))
#'
#' message("testing diff")
#' d64 <- diffinv(rep(.Machine$integer.max, 100), lag=2, differences=2)
#' i64 <- as.integer64(d64)
#' identical(diff(d64, lag=2, differences=2), as.double(diff(i64, lag=2, differences=2)))
#'
#' }
#'
#' \dontrun{
#' message("== Differences between integer64 and int64 ==")
#' require(bit64)
Expand Down
12 changes: 0 additions & 12 deletions R/integer64.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ NULL
#' x
#' x[]
#' x[,2:3]
#' \dontshow{
#' r <- c(runif64(1e3, lim.integer64()[1], lim.integer64()[2]), NA, -2:2)
#' stopifnot(identical(r, as.integer64(as.bitstring(r))))
#' }
#' @name extract.replace.integer64
NULL

Expand Down Expand Up @@ -165,14 +161,6 @@ NULL
#' @seealso [xor.integer64()] [integer64()]
#' @examples
#' sqrt(as.integer64(1:12))
#' \dontshow{
#' i <- -999:999
#' for (s in -3:3){
#' r <- as.integer64(round(as.integer(i), s))
#' r64 <- round(as.integer64(i), s)
#' stopifnot(identical(r,r64))
#' }
#' }
#' @name format.integer64
NULL

Expand Down
17 changes: 0 additions & 17 deletions R/patch64.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@
# %table(c(1,1,2),as.integer64(c(3,4,4)))
#'
#' order(as.integer64(c(1,NA,2)))
#'
#' \dontshow{
#' stopifnot(identical(match(as.integer64(2), as.integer64(0:3)), match(2, 0:3)))
#' stopifnot(identical(as.integer64(2) %in% as.integer64(0:3), 2 %in% 0:3))
#'
#' stopifnot(identical(unique(as.integer64(c(1,1,2))), as.integer64(unique(c(1,1,2)))))
#' stopifnot(identical(rank(as.integer64(c(1,1,2))), rank(c(1,1,2))))
#'
# 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))))
#'
#' stopifnot(identical(order(as.integer64(c(1,NA,2))), order(c(1,NA,2))))
#' stopifnot(identical(order(as.integer64(c(1,NA,2)), decreasing=TRUE), order(c(1,NA,2), decreasing=TRUE)))
#' }
#'
#' @keywords methods
#' @name bit64S3
NULL
Expand Down
Loading
Loading