tests/testthat/test.force_categorical.r

context("force_categorical")

library(magrittr)
library(tibble)
library(testthat)

rm(list = ls())
set.seed(0)
numcol <- 1:10 %>% as.numeric()
intcol <- numcol %>% as.integer()

#### parameters invalid on its face ####

# bad df
expect_error(
  NULL %>%
    force_categorical(),
  "variables %>% is.tibble()",
  fixed = T)

# bad columns
expect_error(
  data.frame(
    a = numcol,
    b = intcol) %>%
    identify_variables() %>%
    force_categorical(NULL),
  "columns %>% is.vector()",
  fixed = T)

#### normal analysis ####

# normal identify
actual <-
  data.frame(
    a = numcol,
    b = intcol) %>%
  identify_variables() %>%
  force_categorical("b")
expected <-
  tibble(
    name = c("a", "b"),
    class = c("numeric", "integer"),
    type = c("continuous", "categorical"))
expect_equal(actual, expected)
markanewman/mndredge documentation built on May 9, 2019, 5:52 a.m.