aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests
diff options
context:
space:
mode:
Diffstat (limited to 'R/pkg/inst/tests')
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R18
1 files changed, 18 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index 7aa03a9048..607bd9c12f 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -2280,6 +2280,24 @@ test_that("createDataFrame sqlContext parameter backward compatibility", {
expect_equal(collect(before), collect(after))
})
+test_that("randomSplit", {
+ num <- 4000
+ df <- createDataFrame(data.frame(id = 1:num))
+
+ weights <- c(2, 3, 5)
+ df_list <- randomSplit(df, weights)
+ expect_equal(length(weights), length(df_list))
+ counts <- sapply(df_list, count)
+ expect_equal(num, sum(counts))
+ expect_true(all(sapply(abs(counts / num - weights / sum(weights)), function(e) { e < 0.05 })))
+
+ df_list <- randomSplit(df, weights, 0)
+ expect_equal(length(weights), length(df_list))
+ counts <- sapply(df_list, count)
+ expect_equal(num, sum(counts))
+ expect_true(all(sapply(abs(counts / num - weights / sum(weights)), function(e) { e < 0.05 })))
+})
+
unlink(parquetPath)
unlink(jsonPath)
unlink(jsonPathNa)