Skip to content

Commit

Permalink
add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhoffa committed Jan 17, 2024
1 parent ab0bb24 commit 3ecfeb5
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/testthat/test-plot_emission_intensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,72 @@ test_that("throws expected warning about API change", {
class = "warning"
)
})

test_that("works well with `scale_colour_r2dii`", {
#TODO: Check if this belongs here or in `test-scale_colour_r2dii.R`
data <- sda %>%
filter(region == "global")

input_levels <- c(
"projected",
"corporate_economy",
"target_demo",
"adjusted_scenario_demo"
)

input_color_scale <-
c(
"dark_blue",
"green",
"grey",
"ruby_red"
)

input_color_scale_hex <- data.frame(label = input_color_scale) %>%
left_join(palette_colours, by = "label") %>%
pull(hex)

expected_output <- data.frame(
levels = input_levels,
hex = input_color_scale_hex
)

p <- data %>%
dplyr::mutate(
emission_factor_metric = factor(
.data$emission_factor_metric,
levels = input_levels
)
) %>%
plot_emission_intensity() +
scale_colour_r2dii(
labels = input_color_scale
)

# print the levels that colours are applied to
ordered_output_levels <- levels(match_lines_order(p$data))

# print the actual colour scales of the plot
ordered_output_colour_scale <- p$scales$get_scales("colour")$palette(
length(ordered_output_levels)
)

plot_output <- data.frame(
levels = ordered_output_levels,
hex = ordered_output_colour_scale
)

out <- left_join(
plot_output,
expected_output,
by = "levels",
suffix = c("_out", "_expected")
) %>%
split(.$levels)

expect_equal(out$projected$hex_out, out$projected$hex_expected)
expect_equal(out$corporate_economy$hex_out, out$corporate_economy$hex_expected)
expect_equal(out$target_demo$hex_out, out$target_demo$hex_expected)
expect_equal(out$adjusted_scenario_demo$hex_out, out$adjusted_scenario_demo$hex_expected)

})

0 comments on commit 3ecfeb5

Please sign in to comment.