From 22365ef53eb792796862613c3d6b1a221d46dc42 Mon Sep 17 00:00:00 2001 From: Yanbo Liang Date: Sun, 18 Sep 2016 03:04:28 -0700 Subject: [PATCH 1/3] Fix print of Kolmogorov-Smirnov test summary --- R/pkg/R/mllib.R | 16 +++++++++------- R/pkg/inst/tests/testthat/test_mllib.R | 14 -------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/R/pkg/R/mllib.R b/R/pkg/R/mllib.R index 234b208166b54..98db367a856ee 100644 --- a/R/pkg/R/mllib.R +++ b/R/pkg/R/mllib.R @@ -1398,20 +1398,22 @@ setMethod("summary", signature(object = "KSTest"), distParams <- unlist(callJMethod(jobj, "distParams")) degreesOfFreedom <- callJMethod(jobj, "degreesOfFreedom") - list(p.value = pValue, statistic = statistic, nullHypothesis = nullHypothesis, - nullHypothesis.name = distName, nullHypothesis.parameters = distParams, - degreesOfFreedom = degreesOfFreedom) + ans <- list(p.value = pValue, statistic = statistic, nullHypothesis = nullHypothesis, + nullHypothesis.name = distName, nullHypothesis.parameters = distParams, + degreesOfFreedom = degreesOfFreedom, jobj = jobj) + class(ans) <- "summary.KSTest" + ans }) # Prints the summary of KSTest #' @rdname spark.kstest -#' @param x test result object of KSTest by \code{spark.kstest}. +#' @param x summary object of KSTest returned by \code{summary}. #' @export #' @note print.summary.KSTest since 2.1.0 print.summary.KSTest <- function(x, ...) { - jobj <- x@jobj + jobj <- x$jobj summaryStr <- callJMethod(jobj, "summary") - cat(summaryStr) - invisible(summaryStr) + cat(summaryStr, "\n") + invisible(x) } diff --git a/R/pkg/inst/tests/testthat/test_mllib.R b/R/pkg/inst/tests/testthat/test_mllib.R index 5b1404c621bd1..aaea71c924a0e 100644 --- a/R/pkg/inst/tests/testthat/test_mllib.R +++ b/R/pkg/inst/tests/testthat/test_mllib.R @@ -761,13 +761,6 @@ 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) @@ -775,13 +768,6 @@ 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.44003[0-9]* \\n", - "pValue = 0.09470[0-9]* \\n", - ".*"), perl = TRUE) }) sparkR.session.stop() From 1e5b6c254ce9715d1bf2052ccc44b6e8065f4430 Mon Sep 17 00:00:00 2001 From: Yanbo Liang Date: Sun, 18 Sep 2016 06:17:56 -0700 Subject: [PATCH 2/3] Add test to check the R print method is doing something. --- R/pkg/inst/tests/testthat/test_mllib.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/pkg/inst/tests/testthat/test_mllib.R b/R/pkg/inst/tests/testthat/test_mllib.R index aaea71c924a0e..f5bf689f9883a 100644 --- a/R/pkg/inst/tests/testthat/test_mllib.R +++ b/R/pkg/inst/tests/testthat/test_mllib.R @@ -760,6 +760,7 @@ 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) + expect_true(length(capture.output(stats)) != 0) testResult <- spark.kstest(df, "test", "norm", -0.5) stats <- summary(testResult) @@ -768,6 +769,7 @@ 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) + expect_true(length(capture.output(stats)) != 0) }) sparkR.session.stop() From 5c5c4ff8ae3ef9d050c404007ac2c114353fb2cc Mon Sep 17 00:00:00 2001 From: Yanbo Liang Date: Tue, 20 Sep 2016 06:35:23 -0700 Subject: [PATCH 3/3] Update test case. --- R/pkg/inst/tests/testthat/test_mllib.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/pkg/inst/tests/testthat/test_mllib.R b/R/pkg/inst/tests/testthat/test_mllib.R index f5bf689f9883a..24c40a88231a7 100644 --- a/R/pkg/inst/tests/testthat/test_mllib.R +++ b/R/pkg/inst/tests/testthat/test_mllib.R @@ -760,7 +760,7 @@ 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) - expect_true(length(capture.output(stats)) != 0) + expect_match(capture.output(stats)[1], "Kolmogorov-Smirnov test summary:") testResult <- spark.kstest(df, "test", "norm", -0.5) stats <- summary(testResult) @@ -769,7 +769,7 @@ 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) - expect_true(length(capture.output(stats)) != 0) + expect_match(capture.output(stats)[1], "Kolmogorov-Smirnov test summary:") }) sparkR.session.stop()