Skip to content

Commit

Permalink
Fix test flakiness (#1351)
Browse files Browse the repository at this point in the history
* Fix test flakiness

* Just double the sample size instead

* added seed

---------

Co-authored-by: topepo <mxkuhn@gmail.com>
  • Loading branch information
MichaelChirico and topepo authored Nov 25, 2024
1 parent 21d34a5 commit 0aadaf2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/caret/tests/testthat/test_Dummies.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ check_dummies <- function(x, expected = NULL) {
expect_equal(exp_names, res_names)

foosbarsbars <- dummies <- dummyVars(formula = id ~.,
data = test_data,
sep = '-',
levelsOnly = TRUE)
data = test_data,
sep = '-',
levelsOnly = TRUE)

exp_names_lvls <- paste(1:9)
res_names_lvls <- colnames(predict(foosbarsbars, test_data))
Expand All @@ -120,10 +120,12 @@ check_dummies <- function(x, expected = NULL) {


test_that("Good names for dummies with reocurring patterns", {
set.seed(1)
# 200 all but guarantees (99.999% chance) 1:15 all represented, #1350
data = data.frame(
matrix(
rep(
as.factor(sample.int(15, size = 100, replace = TRUE, prob = rep(1 / 15, 15))
as.factor(sample.int(15, size = 200, replace = TRUE, prob = rep(1 / 15, 15))
),
15
),
Expand All @@ -137,4 +139,3 @@ test_that("Good names for dummies with reocurring patterns", {
res_names_lvls <- colnames(predict(essai_dummyVars, data))
expect_true(all(exp_names_lvls %in% res_names_lvls))
})

0 comments on commit 0aadaf2

Please sign in to comment.