Skip to content

Commit

Permalink
refactor (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashsinghal authored Jun 17, 2024
1 parent 9007c2a commit 181b6c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/add_transition_risk_category.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_transition_risk_category <- function(data) {

mutate(data, transition_risk_category = ifelse(
is.na(.data[[col_transition_risk_score()]]),
NA,
NA_character_,
categorize_risk(
.data[[col_transition_risk_score()]],
.data[[col_tr_low_threshold()]],
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-add_transition_risk_category.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ test_that("if input data lacks crucial columns, errors gracefully", {
bad <- select(input_data, -all_of(crucial))
expect_error(add_transition_risk_category(bad), crucial)
})

test_that("if `transition_risk_category` column has only NAs, then class of the column is `character`", {
co2 <- read_csv(toy_emissions_profile_products_ecoinvent()) |>
filter(activity_uuid_product_uuid != "76269c17-78d6-420b-991a-aa38c51b45b7")
all_activities_scenario_sectors <- read_csv(toy_all_activities_scenario_sectors()) |>
filter(activity_uuid_product_uuid == "76269c17-78d6-420b-991a-aa38c51b45b7")
scenarios <- read_csv(toy_sector_profile_any_scenarios())

output <- add_thresholds_transition_risk(
co2,
all_activities_scenario_sectors,
scenarios
) |>
add_transition_risk_category()

expected_class <- "character"
expect_equal(class(output$transition_risk_category), expected_class)
})

0 comments on commit 181b6c4

Please sign in to comment.