tests/testthat/test-rescale_for_against_4.R

library (surveyreader)
library(testthat)
context("Convert 4-level agreement (for-against) categories.")

test_that("correct character conversion takes place", {
  expect_equal( rescale_for_against_4  (column =
                                         c("Strongly in favour",
                                           "Fairly in favour",
                                           "Fairly opposed",
                                           "Strongly opposed",
                                         "DK", "NT/NV"),
                                     na_labels = "default",
                                     return_class = "character"),
                c("strongly_for", "for",
                  "against", "strongly_against",
                  NA, NA)
  )})

test_that("correct numeric conversion takes place", {
  expect_equal( rescale_for_against_4  (column =
                                         c("Strongly in favour",
                                           "Fairly in favour",
                                           "Fairly opposed",
                                           "Strongly opposed",
                                           "DK", "NT/NV"),
                                     na_labels = "default",
                                     return_class = "numeric"),
    c(2, 1, -1, -2, NA, NA)
  )
})

test_that("function behind wrapper works", {
  expect_equal( rescale_categories  (column =
                                          c("Strongly in favour",
                                            "Fairly in favour",
                                            "Fairly opposed",
                                            "Strongly opposed",
                                            "DK", "NT/NV"),
                                     from = c("Strongly in favour",
                                              "Fairly in favour",
                                              "Fairly opposed",
                                              "Strongly opposed"),
                                     to = c(2,1,-1, -2),
                                        na_labels = "default",
                                        return_class = "numeric"),
                c(2, 1, -1, -2, NA, NA)
  )
})
antaldaniel/surveyreader documentation built on May 16, 2019, 2:29 a.m.