From ea00ca6f8fa64fa137d0844ab57c1a75dd8386d3 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Fri, 7 Apr 2017 09:08:54 -0400 Subject: [PATCH] Unit test for issue #612 --- .../tests/testthat/test_sampling_options.R | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/caret/tests/testthat/test_sampling_options.R b/pkg/caret/tests/testthat/test_sampling_options.R index e199c4a06..24fecaa0a 100644 --- a/pkg/caret/tests/testthat/test_sampling_options.R +++ b/pkg/caret/tests/testthat/test_sampling_options.R @@ -84,3 +84,32 @@ test_that('check missing method', { skip_on_cran() expect_error(getSamplingInfo("plum")) }) + +################################################################### +## + +set.seed(2) +training <- twoClassSim(200, intercept = -10) + +check_samp <- function(x, samp) { + with_form <- train(Class ~ Linear01, data = x, + method = "lda", + trControl = trainControl(method = "cv", + sampling = samp)) + no_form <- train(x = x[, "Linear01", drop = FALSE], + y = x$Class, + method = "lda", + trControl = trainControl(method = "cv", + sampling = samp)) + TRUE +} + +test_that('downsampling with one var for issue #612', { + skip_on_cran() + expect_true(check_samp(training, "down")) + expect_true(check_samp(training, "up")) + expect_true(check_samp(training, "rose")) + expect_true(check_samp(training, "smote")) +}) + +