Skip to content

Commit

Permalink
small test
Browse files Browse the repository at this point in the history
  • Loading branch information
lindadelacombaz committed Apr 30, 2024
1 parent 9c6a7b6 commit 2256ca7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(bar_plot_emission_profile)
export(bar_plot_emission_profile_financial)
export(benchmarks)
export(example_financial)
export(map_region_risk)
export(plot_sankey)
export(scatter_plot_financial)
Expand Down
31 changes: 31 additions & 0 deletions R/utils-test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Construct example financial data
#'
#' @param ... Passed to [tibble()].
#'
#' @return A [tibble()]
#' @keywords internal
#' @export
#'
#' @examples
#' example_financial()
example_financial <- function(bank_id = "a",
amount_total = 10,
company_name = "b",
emission_profile = "medium",
benchmark = "c",
equal_weight_finance = 10,
worst_case_finance = 10,
best_case_finance = 10,
...) {
tibble::tibble(
bank_id = bank_id,
amount_total = amount_total,
company_name = company_name,
emission_profile = emission_profile,
benchmark = benchmark,
equal_weight_finance = equal_weight_finance,
worst_case_finance = worst_case_finance,
best_case_finance = best_case_finance,
...
)
}
31 changes: 31 additions & 0 deletions man/example_financial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions tests/testthat/test-bar_plot_emission_profile_financial.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
test_that("returns an object of the expected class", {
plot <- bar_plot_emission_profile_financial(financial, benchmarks())
data <- example_financial(ep_product = "e")
plot <- bar_plot_emission_profile_financial(data, benchmarks())
expect_s3_class(plot, "ggplot")
})

test_that("returns correct risk category values", {
plot <- bar_plot_emission_profile_financial(financial, benchmarks())
data <- example_financial(ep_product = "e")
plot <- bar_plot_emission_profile_financial(data, benchmarks())
risk_categories <- levels(plot$data$risk_category_var)
expected_risk_categories <- c("low", "medium", "high")
expect_equal(risk_categories, expected_risk_categories)
})

test_that("returns correct benchmarks values", {
plot <- bar_plot_emission_profile_financial(financial, benchmarks())
data <- example_financial(ep_product = "e")
plot <- bar_plot_emission_profile_financial(data, benchmarks())
benchmarks <- unique(plot$data$benchmark)
expected_benchmarks <- financial |>
pull(benchmark) |>
Expand Down

0 comments on commit 2256ca7

Please sign in to comment.