Skip to content

Commit

Permalink
Fix docs. Add test for print function.
Browse files Browse the repository at this point in the history
  • Loading branch information
junyangq committed Sep 1, 2016
1 parent d4b1459 commit 0a8ff80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 4 additions & 7 deletions R/pkg/R/mllib.R
Original file line number Diff line number Diff line change
Expand Up @@ -1329,11 +1329,6 @@ setMethod("write.ml", signature(object = "ALSModel", path = "character"),
#' Users can call \code{summary} to obtain a summary of the test, and \code{print.summary.KSTest}
#' to print out a summary result.
#'
#' @details
#' For more details, see
#' \href{http://spark.apache.org/docs/latest/mllib-statistics.html#hypothesis-testing}{
#' MLlib: Hypothesis Testing}.
#'
#' @param data a SparkDataFrame of user data.
#' @param testCol column name where the test data is from. It should be a column of double type.
#' @param nullHypothesis name of the theoretical distribution tested against. Currently only
Expand All @@ -1347,6 +1342,8 @@ setMethod("write.ml", signature(object = "ALSModel", path = "character"),
#' @rdname spark.kstest
#' @aliases spark.kstest,SparkDataFrame-method
#' @name spark.kstest
#' @seealso \href{http://spark.apache.org/docs/latest/mllib-statistics.html#hypothesis-testing}{
#' MLlib: Hypothesis Testing}
#' @export
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -1404,10 +1401,10 @@ setMethod("summary", signature(object = "KSTest"),
degreesOfFreedom = degreesOfFreedom)
})

# Prints the summary of GeneralizedLinearRegressionModel
# Prints the summary of KSTest

#' @rdname spark.kstest
#' @param x test result object of KS.
#' @param x test result object of \code{spark.kstest}.
#' @export
#' @note print.summary.KSTest since 2.1.0
print.summary.KSTest <- function(x, ...) {
Expand Down
14 changes: 14 additions & 0 deletions R/pkg/inst/tests/testthat/test_mllib.R
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,27 @@ test_that("spark.kstest", {
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()

0 comments on commit 0a8ff80

Please sign in to comment.