init
This commit is contained in:
commit
116abafc09
58 changed files with 5749 additions and 0 deletions
71
tests/testthat/test-palette.R
Normal file
71
tests/testthat/test-palette.R
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
test_that("pmPalette creates color mapping", {
|
||||
colors <- pmPalette(c("#ff0000", "#00ff00", "#0000ff"))
|
||||
|
||||
expect_true("water" %in% names(colors))
|
||||
expect_true("background" %in% names(colors))
|
||||
})
|
||||
|
||||
test_that("pmPalette expands paired colors", {
|
||||
colors <- pmPalette(c("#ff0000", "#00ff00"), categories = c("water", "park"))
|
||||
|
||||
expect_equal(colors$park_a, "#00ff00")
|
||||
expect_equal(colors$park_b, "#00ff00")
|
||||
})
|
||||
|
||||
test_that("pmPalette handles custom categories", {
|
||||
colors <- pmPalette(
|
||||
c("#111", "#222", "#333"),
|
||||
categories = c("water", "buildings", "highway")
|
||||
)
|
||||
|
||||
expect_equal(colors$water, "#111")
|
||||
expect_equal(colors$buildings, "#222")
|
||||
expect_equal(colors$highway, "#333")
|
||||
})
|
||||
|
||||
test_that("pmPalette recycles colors if needed", {
|
||||
colors <- pmPalette(c("#aaa", "#bbb"), categories = c("a", "b", "c", "d"))
|
||||
|
||||
expect_equal(length(colors), 6) # 4 categories + background + earth
|
||||
})
|
||||
|
||||
test_that("pmPalette handles palette functions", {
|
||||
skip_if_not_installed("viridisLite")
|
||||
|
||||
colors <- pmPalette(viridisLite::viridis, n = 5)
|
||||
expect_true("water" %in% names(colors))
|
||||
})
|
||||
|
||||
test_that("pmPaletteStyle creates pm_style", {
|
||||
style <- pmPaletteStyle(c("#1a1a2e", "#16213e", "#0f3460", "#e94560", "#533483"))
|
||||
|
||||
expect_s3_class(style, "pm_style")
|
||||
expect_true(length(style$labelRules) > 0)
|
||||
})
|
||||
|
||||
test_that("pmPaletteStyle respects labels parameter", {
|
||||
style_with <- pmPaletteStyle(c("#000", "#fff"), labels = TRUE)
|
||||
style_without <- pmPaletteStyle(c("#000", "#fff"), labels = FALSE)
|
||||
|
||||
expect_true(length(style_with$labelRules) > 0)
|
||||
expect_equal(length(style_without$labelRules), 0)
|
||||
})
|
||||
|
||||
test_that("pmPaletteStyle uses water_color parameter", {
|
||||
style <- pmPaletteStyle(
|
||||
c("#aaa", "#bbb", "#ccc"),
|
||||
water_color = "#123456"
|
||||
)
|
||||
|
||||
expect_equal(style$colors$water, "#123456")
|
||||
})
|
||||
|
||||
test_that("pmPaletteStyle uses land_color parameter", {
|
||||
style <- pmPaletteStyle(
|
||||
c("#aaa", "#bbb", "#ccc"),
|
||||
land_color = "#fedcba"
|
||||
)
|
||||
|
||||
expect_equal(style$colors$background, "#fedcba")
|
||||
expect_equal(style$colors$earth, "#fedcba")
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue