Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Oct 13, 2020
1 parent e2bc96e commit f67b9c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
2 changes: 2 additions & 0 deletions R/palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ color_palettes <- colour_palettes
#'
#' @export
show_colours <- function( colours = colour_palettes() ) {
## nocov start
graphics::par(mar = c(0, 0, 0, 0) + 0.1)

graphics::plot(0, 0, type = "n", axes = FALSE, bty = "n", xlab = "", ylab = "",
Expand All @@ -166,6 +167,7 @@ show_colours <- function( colours = colour_palettes() ) {
ytop = - 0.15-i, ybottom = -0.8-i,
col = cols, border = NA)
}
## nocov end
}

#' Viridis
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-interleaved.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ test_that("interleaved vector returned", {
## Testing where repeats is a different length
## TODO:
## - test where repeats.length != x.length
x <- 1:5
repeats <- c(1)
totals <- sum(repeats)
res <- colourvalues:::rcpp_colour_values_rgb_interleaved(x, "viridis", 1.0, repeats, totals)
expect_true(length(res) == totals * 4)
m <- matrix( res, byrow = T, ncol = 4)

x <- c(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5)
y <- colour_values_rgb(x)
expect_equal( m, y )
# x <- 1:5
# repeats <- c(1)
# totals <- sum(repeats)
# res <- colourvalues:::rcpp_colour_values_rgb_interleaved(x, "viridis", 1.0, repeats, totals)
# expect_true(length(res) == totals * 4)
# m <- matrix( res, byrow = T, ncol = 4)
#
# x <- c(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5)
# y <- colour_values_rgb(x)
# expect_equal( m, y )

})

Expand Down
26 changes: 10 additions & 16 deletions tests/testthat/test-palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ context("palettes")

test_that("palettes are returned", {

dfv <- viridis()
dfp <- plasma()
dfi <- inferno()
dfm <- magma()
dfc <- cividis()
expect_true(nrow(dfv) == 256 & ncol(dfv) == 3)
expect_true(nrow(dfp) == 256 & ncol(dfp) == 3)
expect_true(nrow(dfi) == 256 & ncol(dfi) == 3)
expect_true(nrow(dfm) == 256 & ncol(dfm) == 3)
expect_true(nrow(dfc) == 256 & ncol(dfc) == 3)

expect_error(colour_values(1:5, palette = "mypalette"), "unknown palette")

expect_silent(colour_values(1, palette = "viridis"))
expect_silent(colour_values(1, palette = "plasma"))
expect_silent(colour_values(1, palette = "inferno"))
expect_silent(colour_values(1, palette = "magma"))
expect_silent(colour_values(1, palette = "cividis"))
all_palettes <- color_palettes()
expect_true( length(all_palettes) == 52 )

for( palette in all_palettes ) {
expect_silent( colour_values(1, palette = palette ))
res <- colourvalues::get_palette( palette )
expect_true( ncol( res ) == 3 & nrow( res ) == 256 )
}

expect_error( colourvalues::get_palette("test"), "not a valid palette" )

})

Expand Down

0 comments on commit f67b9c0

Please sign in to comment.