tests/testthat/test-mc_indicator.R

library (surveyreader)
library(testthat)
context("Converting multiple choice character values to numeric values.")
mc_column_1 <- c("first option", NA, "first option", "NA" )
mc_column_2 <- c(NA, "second option", NA, "NA")

test_that("correct numeric conversion takes place", {
  expect_equal(
    sum (mc_indicator ( column     = mc_column_1,
                        selected   = 1,
                        unselected = 0,
                        missing    = 0,
                        na_id      = NA), na.rm = FALSE),
    3
  )
  expect_equal(
    sum (mc_indicator ( column     = mc_column_1,
                        selected   = 1,
                        unselected = 0,
                        missing    = 0,
                        na_id      = "NA"), na.rm = FALSE),
    2
  )
  expect_equal(
    sum (mc_indicator ( column = mc_column_2,
                        selected = 2,
                        missing = NA,
                        na_id = "NA"), na.rm = TRUE),
    2
  )
})
antaldaniel/surveyreader documentation built on May 16, 2019, 2:29 a.m.