Просмотр исходного кода

Update {lighten,darken}_color() documentation and add tests

tags/v0.3.0
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
283b21c15c
3 измененных файлов: 27 добавлений и 2 удалений
  1. +2
    -1
      R/color.R
  2. +2
    -1
      man/lighten_darken_color.Rd
  3. +23
    -0
      tests/testthat/test-color.R

+ 2
- 1
R/color.R Просмотреть файл

#' @description Produces a linear blend of the color with white or black. #' @description Produces a linear blend of the color with white or black.
#' @param color_hex A character string representing a hex color #' @param color_hex A character string representing a hex color
#' @param strength The "strength" of the blend with white or black, #' @param strength The "strength" of the blend with white or black,
#' 0 low to 1 high.
#' where 0 is entirely the original color and 1 is entirely white
#' (`lighten_color()`) or black (`darken_color()`).
#' @name lighten_darken_color #' @name lighten_darken_color
NULL NULL



+ 2
- 1
man/lighten_darken_color.Rd Просмотреть файл

\item{color_hex}{A character string representing a hex color} \item{color_hex}{A character string representing a hex color}


\item{strength}{The "strength" of the blend with white or black, \item{strength}{The "strength" of the blend with white or black,
0 low to 1 high.}
where 0 is entirely the original color and 1 is entirely white
(\code{lighten_color()}) or black (\code{darken_color()}).}
} }
\description{ \description{
Produces a linear blend of the color with white or black. Produces a linear blend of the color with white or black.

+ 23
- 0
tests/testthat/test-color.R Просмотреть файл

expect_error(full_length_hex("#00000Z")) expect_error(full_length_hex("#00000Z"))
}) })
}) })


describe("lighten_color() and darken_color()", {
it("errors if strength not in [0, 1]", {
expect_error(lighten_color("#123", 9))
expect_error(darken_color("#123", 9))
})

it("returns original color if strength = 0", {
expect_equal(lighten_color("#808080", 0), "#808080")
expect_equal(darken_color("#808080", 0), "#808080")
})

it("returns entire blend color if strength = 0", {
expect_equal(lighten_color("#808080", 1), "#FFFFFF")
expect_equal(darken_color("#808080", 1), "#000000")
})

it("returns midpoint if strength = 0.5", {
expect_equal(lighten_color("#000000", 0.5), "#7F7F7F")
expect_equal(darken_color("#FFFFFF", 0.5), "#7F7F7F")
})
})

Загрузка…
Отмена
Сохранить