diff options
Diffstat (limited to 'R/pkg/inst/tests/testthat/test_mllib.R')
-rw-r--r-- | R/pkg/inst/tests/testthat/test_mllib.R | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/testthat/test_mllib.R b/R/pkg/inst/tests/testthat/test_mllib.R index 825a24073b..ca25f2c7e8 100644 --- a/R/pkg/inst/tests/testthat/test_mllib.R +++ b/R/pkg/inst/tests/testthat/test_mllib.R @@ -742,4 +742,38 @@ test_that("spark.als", { unlink(modelPath) }) +test_that("spark.kstest", { + data <- data.frame(test = c(0.1, 0.15, 0.2, 0.3, 0.25, -1, -0.5)) + df <- createDataFrame(data) + testResult <- spark.kstest(df, "test", "norm") + stats <- summary(testResult) + + rStats <- ks.test(data$test, "pnorm", alternative = "two.sided") + + expect_equal(stats$p.value, rStats$p.value, tolerance = 1e-4) + expect_equal(stats$statistic, unname(rStats$statistic), tolerance = 1e-4) + + printStr <- print.summary.KSTest(testResult) + expect_match(printStr, paste0("Kolmogorov-Smirnov test summary:\\n", + "degrees of freedom = 0 \\n", + "statistic = 0.38208[0-9]* \\n", + "pValue = 0.19849[0-9]* \\n", + ".*"), perl = TRUE) + + testResult <- spark.kstest(df, "test", "norm", -0.5) + stats <- summary(testResult) + + rStats <- ks.test(data$test, "pnorm", -0.5, 1, alternative = "two.sided") + + expect_equal(stats$p.value, rStats$p.value, tolerance = 1e-4) + expect_equal(stats$statistic, unname(rStats$statistic), tolerance = 1e-4) + + printStr <- print.summary.KSTest(testResult) + expect_match(printStr, paste0("Kolmogorov-Smirnov test summary:\\n", + "degrees of freedom = 0 \\n", + "statistic = 0.44003[0-9]* \\n", + "pValue = 0.09470[0-9]* \\n", + ".*"), perl = TRUE) +}) + sparkR.session.stop() |