tests/testthat/test-likert.R

# Input -------------------------------------------------------------------





test_that("Likert input: Numerical, without labels", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'))
  )
})

test_that("Likert input: Numerical, with labels", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'),
                 labels = c('Strongly disagree', 'Disagree','Neutral','Agree','Strongly agree'))
  )
})


test_that("Likert input: Numerical, with labels", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'),
                 labels = c('Strongly disagree', 'Disagree','Neutral','Agree','Strongly agree'))
  )
})


test_that("Likert input: Factor, without labels", {
  berlinbears$c_diet <- factor(berlinbears$c_diet, levels = c('low', 'medium', 'high'))
  berlinbears$c_exercise <- factor(berlinbears$c_exercise, levels = c('low', 'medium', 'high'))

  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('c_'))
  )
})


test_that("Likert input: Character, without labels", {
  expect_error(
    matrix_likert(berlinbears, dplyr::starts_with('c_'))
  )
})

test_that("Likert input: Character, with labels", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('c_'), labels = c('low', 'medium', 'high'))
  )
})

test_that("Likert input: incorrect number of labels", {
  expect_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'), labels = c('low', 'medium', 'high'))
  )
})

test_that("Likert input: three levels, no colors", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('c_'),
                 labels = c('low', 'medium', 'high'))
  )
})



# Graphing ----------------------------------------------------------------



test_that("Likert graph: Default, without weights", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'))
  )
})

test_that("Likert graph: Default, with weights", {
  expect_no_error(
    matrix_likert(berlinbears, dplyr::starts_with('p_'),
                 weights = weights)
  )
})


test_that("Likert graph: Incorrect number of labels", {
  expect_error(
    matrix_likert(berlinbears,
                 dplyr::starts_with('p_'),
                 labels = c('Strongly disagree', 'Disagree','Neutral','Agree'))
  )
})

test_that("Likert graph: NA.RM = FALSE, Incorrect number of labels", {
  expect_error(
    matrix_likert(berlinbears,
                 dplyr::starts_with('p_'),
                 na.rm = FALSE)
  )
})

Try the surveyexplorer package in your browser

Any scripts or data that you put into this service are public.

surveyexplorer documentation built on June 22, 2024, 9:35 a.m.