stRoke/tests/testthat/test-quantile_cut.R

29 lines
1.0 KiB
R
Raw Normal View History

2022-09-23 09:14:47 +02:00
test_that("quatile_cut() works for detail.list==FALSE", {
result <- quantile_cut(iris$Sepal.Length,3,detail.list=FALSE)
expect_equal(length(levels(result)), 3)
expect_s3_class(result, "factor")
})
################################################################################
test_that("quatile_cut() works for detail.list==FALSE", {
result <- quantile_cut(iris$Sepal.Length,3,detail.list=TRUE)
expect_length(result, 2)
expect_type(result, "list")
})
2023-01-03 14:12:29 +01:00
################################################################################
# Test created using remotes::install_github("JamesHWade/gpttools") unit test addin.
test_that("quantile_cut works correctly", {
x <- runif(100)
groups <- 5
y <- runif(100)
expect_equal(quantile_cut(x, groups, y, na.rm = TRUE),
cut(x, quantile(y, probs = seq(0, 1, 1/groups), na.rm = TRUE, names = TRUE, type = 7),
include.lowest = TRUE, labels = NULL, ordered_result = FALSE))
})
################################################################################