😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

67 lines
1.8KB

  1. # test_that()
  2. describe("prepare_colors()", {
  3. it("returns NULL if NULL or missing", {
  4. expect_null(prepare_colors())
  5. expect_null(prepare_colors(NULL))
  6. expect_null(prepare_colors(list()))
  7. })
  8. it("requires a named vector or list", {
  9. expect_error(prepare_colors("#00FF00"))
  10. })
  11. it("requires valid CSS names", {
  12. expect_error(prepare_colors(c("light blue" = "#88f")))
  13. expect_error(prepare_colors(c("light/blue" = "#88f")))
  14. })
  15. it("returns list with color_name and value for each color", {
  16. colors <- c('test' = "#4ed4ed")
  17. prepared <- prepare_colors(colors)
  18. expect_equal(names(prepared[[1]]), c("color_name", "value"))
  19. expect_equal(prepared[[1]]$color_name, names(colors)[[1]])
  20. expect_equal(prepared[[1]]$value, colors[[1]])
  21. })
  22. })
  23. describe("full_length_hex()", {
  24. it("makes 3-length hex to 6-length", {
  25. expect_equal(full_length_hex("#123"), "#112233")
  26. })
  27. it("keeps length 6 hex", {
  28. expect_equal(full_length_hex("#123456"), "#123456")
  29. })
  30. it("errors if not a hex color", {
  31. expect_error(full_length_hex("123abc"))
  32. expect_error(full_length_hex("#1234567"))
  33. expect_error(full_length_hex("#00000Z"))
  34. })
  35. })
  36. describe("lighten_color() and darken_color()", {
  37. it("errors if strength not in [0, 1]", {
  38. expect_error(lighten_color("#123", 9))
  39. expect_error(darken_color("#123", 9))
  40. })
  41. it("returns original color if strength = 0", {
  42. expect_equal(lighten_color("#808080", 0), "#808080")
  43. expect_equal(darken_color("#808080", 0), "#808080")
  44. })
  45. it("returns entire blend color if strength = 0", {
  46. expect_equal(lighten_color("#808080", 1), "#FFFFFF")
  47. expect_equal(darken_color("#808080", 1), "#000000")
  48. })
  49. it("returns midpoint if strength = 0.5", {
  50. expect_equal(lighten_color("#000000", 0.5), "#7F7F7F")
  51. expect_equal(darken_color("#FFFFFF", 0.5), "#7F7F7F")
  52. })
  53. })