tests/testthat/test-add_index.R

context("Add index")

test_that("add_index adds variable", {

  WoJ_i <- WoJ %>%
    add_index(trust_politics,
              trust_parliament,
              trust_government,
              trust_parties,
              trust_politicians)

  WoJ_is <- WoJ %>%
    add_index(trust_politics,
              trust_parliament,
              trust_government,
              trust_parties,
              trust_politicians,
              type = "sum")

    expect_equal(ncol(WoJ) + 1, ncol(WoJ_i))
    expect_equal(ncol(WoJ) + 1, ncol(WoJ_is))
})

test_that("add_index adds attribute 'index_of'", {

  WoJ_i <- WoJ %>%
    add_index(trust_politics,
              trust_parliament,
              trust_government,
              trust_parties,
              trust_politicians)

  expect_true(!is.null(attr(WoJ_i$trust_politics, "index_of")))
})

test_that("add_index works with tidyselect", {

  WoJ_i <- WoJ %>%
    add_index(trust_politics,
              tidyselect::starts_with('trust'))

  expect_equal(ncol(WoJ) + 1, ncol(WoJ_i))
})

Try the tidycomm package in your browser

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

tidycomm documentation built on Sept. 22, 2019, 5:05 p.m.