Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jun 8, 2018
1 parent a72f526 commit ce2aa44
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ Imports:
rstudioapi,
shiny,
jsonlite
Suggests: rnaturalearth, sf
Suggests:
rnaturalearth,
sf,
testthat
RoxygenNote: 6.0.1
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(r2d3maps)

test_check("r2d3maps")
64 changes: 64 additions & 0 deletions tests/testthat/test-scale-breaks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

context("Breaks scale")


test_that("Scale break - one var", {

var <- "Petal.Length"
sclbrk <- r2d3maps:::scale_breaks(data = iris, vars = var)

expect_length(object = sclbrk, n = length(var))
expect_identical(object = names(sclbrk), expected = var)

sclbrkvar <- sclbrk[[var]]

expect_length(object = sclbrkvar, n = 4)
expect_named(object = sclbrkvar, expected = c("range_var", "breaks_var", "colors", "ticks"))

})


test_that("Scale break - several vars", {

var <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
sclbrk <- r2d3maps:::scale_breaks(data = iris, vars = var)

expect_length(object = sclbrk, n = length(var))
expect_identical(object = names(sclbrk), expected = var)

lapply(
X = var,
FUN = function(x) {
sclbrkvar <- sclbrk[[x]]
expect_length(object = sclbrkvar, n = 4)
expect_named(object = sclbrkvar, expected = c("range_var", "breaks_var", "colors", "ticks"))
}
)

})



test_that("Add scale break", {
map <- list(
x = list(
options = list(
data = iris
)
)
)
class(map) <- "r2d3"

resbrk <- add_continuous_breaks(map = map, var = "Petal.Width")
resbrk <- resbrk$x$options$colors

expect_false(object = is.null(resbrk))
expect_length(object = resbrk, n = 4)
expect_identical(object = resbrk$color_type, expected = "continuous-breaks")

})





61 changes: 61 additions & 0 deletions tests/testthat/test-scale-gradient.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

context("Gradient scale")


test_that("Scale gradient - one var", {

var <- "Petal.Length"
sclgdt <- r2d3maps:::scale_gradient(data = iris, vars = var)

expect_length(object = sclgdt, n = length(var))
expect_identical(object = names(sclgdt), expected = var)

sclgdtvar <- sclgdt[[var]]

expect_length(object = sclgdtvar, n = 5)
expect_named(object = sclgdtvar, expected = c("range_var", "scale_var", "colors", "colors_legend", "legend_label"))

})


test_that("Scale gradient - several vars", {

var <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
sclgdt <- r2d3maps:::scale_gradient(data = iris, vars = var)

expect_length(object = sclgdt, n = length(var))
expect_identical(object = names(sclgdt), expected = var)

lapply(
X = var,
FUN = function(x) {
sclgdtvar <- sclgdt[[x]]
expect_length(object = sclgdtvar, n = 5)
expect_named(object = sclgdtvar, expected = c("range_var", "scale_var", "colors", "colors_legend", "legend_label"))
}
)

})


test_that("Add scale gradient", {
map <- list(
x = list(
options = list(
data = iris
)
)
)
class(map) <- "r2d3"

resgdt <- add_continuous_gradient(map = map, var = "Petal.Width")
resgdt <- resgdt$x$options$colors

expect_false(object = is.null(resgdt))
expect_length(object = resgdt, n = 5)
expect_identical(object = resgdt$color_type, expected = "continuous-gradient")

})



0 comments on commit ce2aa44

Please sign in to comment.