       0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0
  5   ˆl–ßi~” T¾R( 	Å+�àS�ÿ�þB gá‘É_CóÂƒh¹ÁÀ¿      ˆÃ‘äÇò 8à_ƒä 	üÿÂƒh¹ÁÀ¿      [none] mq-deadline 
             0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ãƒ _‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ é    ‹      ÕšÛnÛ8†ïû\^ôÎ¦Ùí"•Utí lš©‹b±(Z¤%Â©�Tçéwt°-ÙÚmÞØ3¿'Ò|I†
~›ÝLçÿÞ^ ¿ç®Ðí§¿®.§÷ù<ž2›ÏêÎúƒ!!×áÄ¹üœ�õzÝ_�ûÚÄd~G—¥gÄ:##×çŽãðUPjá+$‚qøF�“.á¥ââé%"ºpVr1Ú„ëÌ+_ÊTô¹Èt?±ýHëNÀud{Ö¦Ûh8ÝÆ’Eª£I!dDl± É‰ŒX3 ÷…(D@ê“B¤É#Xh¾)Ó>w*pÆjØ¢Ê¨4M¸}e©ŒÕ;�ã0�YŒ¬‰&˜ÈH«ò¸L­ú±\bÄR7Áÿ]No¾@qIù×aÀPbÄr‚ßM'×oo&3^³ÎÇNÇ|€˜÷8¼bÖ¡Ls¹”‚?ü±þ(Ÿ>à¬Ž™	™;©Õ>” b5Ò©Í°þ‰iGÕ!ü[£Á¢Î`Ü¾¿»¸žÏ.ïê!áå!öÙýâÂâð–¡šI#"§Í¦!¯Óx­6»uQÃedœ8"ÔC'#`0
µRz­Úãc}r$çÔ0ø8ÜÛítòFô†£Þ`ˆ†ãóñ„ž„gÃ?Ï%Lm5Ü‡÷»qÎ†/‡³Â‡�©K1Ãi×R‘2#ÝPŽE�Ñ2ö@'ìl'yŽ•¬O‘mU�á…ÑÂRÎÛ³µDÑ2F«ce0Ù TÛõgY@eàÃÃÔáþ¨çj¡%Âa×÷Hjšë4Åacø‹@¹HÙfR»~â8™	hA+–Æ~) K�raÚOõÞRÛ(œ”µõ3ž¹m†Ôs¶b(�—R†@Hu,#–ÒjÓ<¶Ž5ÁÊ~e;¿[—“!ê”ê)Ünr±tµ¨É:’§XR9—ƒƒªëžÍûŠ5õh‡ŠßP¶äå%'•ÌŠŒB³Ð¨+xˆ¤t&L\.N·–�†q_[^c-ÇO”G­DÍQYBèzihzv÷É�à!RžlìQswBôÍÆ)+7mªy´ãúˆ£aù µb°ÔÞÛßöÆ4|s~öç‹¹§l¹„¦üooËñ°&Õª´H…ÁáÎô£ÚQ¤kh�Ë'tÇõç«4Ž.t¡83š1»Âá±æ!ØzáhÊ-`=€Ã¶ç#LyyÑˆÁ},{Ç[Ë2ÑÞï9¥z×láê–Ý(ey.Tg»î¤ì+^]¬Î>ëiÝS@^óð_Ÿþw¾ŠBš—tR½-�úe¦ÿßX]È/%        	ˆÆ‘äÇò 8à_ƒ	lRÿ?Åƒh¹ÄÃÂ      	       0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0
  5   ˆl–Ðz¾””¾R( J«�rãbS�ÿ�þIK6YF!:ù_� þÆƒdM‹ÅÄÃ ´    library(testthat)
library(recipes)

skip_if_not_installed("modeldata")
data(covers, package = "modeldata")
rec <- recipe(~description, covers) %>%
  step_regex(description, pattern = "(rock|stony)", result = "rocks") %>%
  step_regex(description, pattern = "(rock|stony)", result = "more_rocks")

test_that("default options", {
  rec1 <- rec %>% step_bin2factor(rocks)
  rec1 <- prep(rec1, training = covers)
  res1 <- bake(rec1, new_data = covers)
  expect_true(all(diag(table(res1$rocks, res1$more_rocks)) == 0))
})

test_that("works with logicals", {
  mtcars$vs <- as.logical(mtcars$vs)
  mtcars$am <- as.logical(mtcars$am)

  res <- recipe(~., data = mtcars) %>%
    step_bin2factor(all_logical_predictors()) %>%
    prep() %>%
    bake(new_data = NULL)

  expect_identical(
    factor(mtcars$vs, levels = c(TRUE, FALSE), labels = c("yes", "no")),
    res$vs
  )
  expect_identical(
    factor(mtcars$am, levels = c(TRUE, FALSE), labels = c("yes", "no")),
    res$am
  )
})


test_that("nondefault options", {
  rec2 <- rec %>% step_bin2factor(rocks, levels = letters[2:1])
  rec2 <- prep(rec2, training = covers)
  res2 <- bake(rec2, new_data = covers)
  expect_true(all(diag(table(res2$rocks, res2$more_rocks)) == 0))
})


test_that("bad options", {
  rec3 <- rec %>% step_bin2factor(description)
  expect_snapshot(error = TRUE,
    prep(rec3, training = covers)
  )
  expect_snapshot(error = TRUE,
    rec %>% step_bin2factor(rocks, levels = letters[1:5])
  )
  expect_snapshot(error = TRUE,
    rec %>% step_bin2factor(rocks, levels = 1:2)
  )
})


test_that("printing", {
  rec2 <- rec %>% step_bin2factor(rocks, levels = letters[2:1])
  expect_snapshot(print(rec2))
  expect_snapshot(prep(rec2))
})


test_that("choose reference level", {
  rec4 <- rec %>% step_bin2factor(rocks, ref_first = FALSE)
  rec4 <- prep(rec4, training = covers)
  res4 <- bake(rec4, new_data = covers)
  expect_true(all(res4$rocks[res4$more_rocks == 1] == "yes"))
  expect_true(all(res4$rocks[res4$more_rocks == 0] == "no"))
  expect_true(levels(res4$rocks)[1] == "no")
})

test_that("empty selection prep/bake is a no-op", {
  rec1 <- recipe(mpg ~ ., mtcars)
  rec2 <- step_bin2factor(rec1)

  rec1 <- prep(rec1, mtcars)
  rec2 <- prep(rec2, mtcars)

  baked1 <- bake(rec1, mtcars)
  baked2 <- bake(rec2, mtcars)

  expe