inst/tests/test-is.wholenumber.r

# Set an acceptable tolerance for floating point comparisons
tol <- .Machine$double.eps^0.5

# Returns TRUE for whole numbers of numeric class
expect_that(all(is.wholenumber(as.numeric(c(1, 2, 3, 4)))), is_true())

# Returns TRUE for whole numbers of integer class
expect_that(all(is.wholenumber(as.integer(c(1, 2, 3, 4)))), is_true())

# Returns FALSE on numeric inputs with decimals
expect_that(all(is.wholenumber(c(1, 2, 3, 4) + tol)), is_false())

# Throws an error on character input
expect_that(all(is.wholenumber(as.character(c(1, 2, 3, 4)))), throws_error())

Try the tbdiag package in your browser

Any scripts or data that you put into this service are public.

tbdiag documentation built on May 2, 2019, 7:59 a.m.