| 1 |
cols <- c("#404040", "#8FBC8F", "#FFFFE0", "#7AC5CD", "#66CDAA", "#1E90FF", |
| 2 |
"#CDC0B0", "#CD0000", "#7A67EE", "#FFFACD") |
| 3 |
truth <- matrix(c(64L, 143L, 255L, 122L, 102L, 30L, 205L, 205L, 122L, |
| 4 |
255L, 64L, 188L, 255L, 197L, 205L, 144L, 192L, 0L, 103L, 250L, |
| 5 |
64L, 143L, 224L, 205L, 170L, 255L, 176L, 0L, 238L, 205L), |
| 6 |
ncol = 3, dimnames = list(NULL, c("r", "g", "b"))) |
| 7 |
test_that("colours can be decoded", { |
| 8 |
expect_equal(decode_colour(cols), truth) |
| 9 |
expect_equal(decode_colour(cols, to = 'cmy'), convert_colour(truth, 'rgb', 'cmy')) |
| 10 |
expect_equal(decode_colour(cols, to = 'cmyk'), convert_colour(truth, 'rgb', 'cmyk')) |
| 11 |
expect_equal(decode_colour(cols, to = 'hsl'), convert_colour(truth, 'rgb', 'hsl')) |
| 12 |
expect_equal(decode_colour(cols, to = 'hsb'), convert_colour(truth, 'rgb', 'hsb')) |
| 13 |
expect_equal(decode_colour(cols, to = 'hsv'), convert_colour(truth, 'rgb', 'hsv')) |
| 14 |
expect_equal(decode_colour(cols, to = 'lab'), convert_colour(truth, 'rgb', 'lab')) |
| 15 |
expect_equal(decode_colour(cols, to = 'hunterlab'), convert_colour(truth, 'rgb', 'hunterlab')) |
| 16 |
expect_equal(decode_colour(cols, to = 'lch'), convert_colour(truth, 'rgb', 'lch')) |
| 17 |
expect_equal(decode_colour(cols, to = 'luv'), convert_colour(truth, 'rgb', 'luv')) |
| 18 |
expect_equal(decode_colour(cols, to = 'xyz'), convert_colour(truth, 'rgb', 'xyz')) |
| 19 |
expect_equal(decode_colour(cols, to = 'yxy'), convert_colour(truth, 'rgb', 'yxy')) |
| 20 |
expect_equal(decode_colour(cols, to = 'hcl'), convert_colour(truth, 'rgb', 'hcl')) |
| 21 |
}) |
| 22 |
|
| 23 |
test_that("alpha gets decoded correctly", { |
| 24 |
alpha <- decode_colour( |
| 25 |
paste0(cols[1:6], c("00", "33", "66", "99", "CC", "")), |
| 26 |
alpha = TRUE |
| 27 |
)[, 'alpha'] |
| 28 |
expect_equal(alpha, seq(0, 1, length.out = 6)) |
| 29 |
}) |