Skip to content

Commit

Permalink
fixed bug in set_plot_node_color_scheme() (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored and jayqi committed Sep 25, 2019
1 parent af754d0 commit b76fc35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
11 changes: 7 additions & 4 deletions R/AbstractGraphReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ AbstractGraphReporter <- R6::R6Class(
})
}

if (!all(areColors(palette))) {
notColors <- names(areColors)[areColors == FALSE]
colorChecks <- areColors(palette)
if (!all(colorChecks)) {
notColors <- names(colorChecks)[colorChecks == FALSE]
notColorsTXT <- paste(notColors, collapse = ", ")
log_fatal(sprintf("The following are invalid colors: %s"
, notColorsTXT))
log_fatal(sprintf(
"The following are invalid colors: %s"
, notColorsTXT
))
}

private$plotNodeColorScheme <- list(
Expand Down
25 changes: 23 additions & 2 deletions tests/testthat/test-AbstractGraphReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ test_that("AbstractGraphReporter errors on unimplemented methods", {
}, regexp = "Reporter must set valid graph class")
})

test_that("AbstractGraphReporter$set_plot_node_color_scheme() correctly sets color palette", {
x <- pkgnet:::AbstractGraphReporter$new()
res <- x$.__enclos_env__$private$set_plot_node_color_scheme(
field = "blegh"
, palette = c("red", "blue")
)
color_scheme <- x$.__enclos_env__$private$plotNodeColorScheme
expect_identical(
color_scheme
, list(field = "blegh", palette = c("red", "blue"))
)
})

test_that("AbstractGraphReporter$set_plot_node_color_scheme() correctly rejects bad colors", {
x <- pkgnet:::AbstractGraphReporter$new()
expect_error({
res <- x$.__enclos_env__$private$set_plot_node_color_scheme(
field = "blegh"
, palette = c("#32CD32", "32CD32")
)
}, "The following are invalid color")
})

### HELPER FUNCTIONS

test_that(".igraphAvailableLayouts returns layouts correctly", {
Expand All @@ -73,8 +96,6 @@ test_that(".igraphAvailableLayouts returns layouts correctly", {
})
})



##### TEST TEAR DOWN #####

rm(list = ls())
Expand Down

0 comments on commit b76fc35

Please sign in to comment.