Skip to content

Commit

Permalink
pass
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed Nov 12, 2023
1 parent 665646d commit 7cff9bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions R/emissions_profile_any_add_values_to_categorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#' inputs <- read_csv(toy_emissions_profile_upstream_products())
#' inputs |> emissions_profile_any_add_values_to_categorize()
emissions_profile_any_add_values_to_categorize <- function(data) {
if (hasName(data, "values_to_categorize")) {
return(data)
}

benchmarks <- set_names(epa_benchmarks(data), flat_benchmarks(data))
map_df(benchmarks, ~ add_rank(data, .x), .id = "grouped_by")
}
Expand Down
20 changes: 13 additions & 7 deletions tests/testthat/test-emissions_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ test_that("it uses pre-computed `values_to_categorize` from 'co2' (#603)", {
!!aka("co2footprint") := c(1, 2)
)

out <- emissions_profile(companies, co2)
computed <- unique(unnest_product(out)$risk_category)
lacks_values_to_categorize <- !hasName(co2, "values_to_categorize")
stopifnot(lacks_values_to_categorize)
out1 <- emissions_profile(companies, co2)
using_computed_values <- unique(unnest_product(out1)$risk_category)

pre_computed <- co2
pre_computed$values_to_categorize <- c(999, 999)
out <- emissions_profile(companies, pre_computed)
pre_computed <- unique(unnest_product(out)$risk_category)
pre_computed <- emissions_profile_any_add_values_to_categorize(co2)
has_values_to_categorize <- hasName(pre_computed, "values_to_categorize")
stopifnot(has_values_to_categorize)

expect_false(identical(computed, pre_computed))
yields_a_different_risk_category <- 999
pre_computed$values_to_categorize <- yields_a_different_risk_category
out2 <- emissions_profile(companies, pre_computed)
using_pre_computed_values <- unique(unnest_product(out2)$risk_category)

expect_false(identical(using_computed_values, using_pre_computed_values))
})

0 comments on commit 7cff9bf

Please sign in to comment.