| #' @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 | ||||
| \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. |
| 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") | |||||
| }) | |||||
| }) |