tests/testthat/test-paletteer_dynamic.R

test_that("paletteer_dynamic return correct number of colors", {
  expect_length(paletteer_dynamic("ggthemes_solarized::green", 1), 1)
  expect_length(paletteer_dynamic("ggthemes_solarized::green", 3), 3)
  expect_length(paletteer_dynamic("ggthemes_solarized::green", 8), 8)
})

test_that("paletteer_dynamic returns characters", {
  expect_type(paletteer_dynamic("ggthemes_solarized::green", 3), "character")
})

test_that("paletteer_dynamic returns something when n is unspecified", {
  expect_error(paletteer_dynamic("ggthemes_solarized::green"))
})

test_that("paletteer_dynamic throws an error when n is specified too high", {
  expect_error(paletteer_dynamic("ggthemes_solarized::green", 100))
})

test_that("direction works correctly in paletteer_dynamic", {
  expect_equal(
    paletteer_dynamic("ggthemes_solarized::green", 3, direction = 1),
    prismatic::color(c("#859900", "#dc322f", "#268bd2"))
  )
  expect_equal(
    paletteer_dynamic("ggthemes_solarized::green", 3, direction = -1),
    prismatic::color(c("#268bd2", "#dc322f", "#859900"))
  )
  expect_error(paletteer_dynamic("ggthemes_solarized::green", 3, direction = 10))
})

test_that("paletteer_dynamic works with quoted palettes", {
  expect_equal(
    paletteer_dynamic(`"ggthemes_solarized::green"`, 3),
    paletteer_dynamic("ggthemes_solarized::green", 3)
  )
})

test_that("paletteer_dynamic works when called from another function", {
  new_function <- function(x) {
    paletteer_dynamic(x, 4)
  }

  expect_equal(
    new_function("ggthemes_solarized::green"),
    paletteer_dynamic("ggthemes_solarized::green", 4)
  )
})

Try the paletteer package in your browser

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

paletteer documentation built on May 29, 2024, 11:21 a.m.