Skip to content

Commit

Permalink
Meet Tilman's requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed May 15, 2024
1 parent 112ad0f commit bb7c2a2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
30 changes: 30 additions & 0 deletions tests/testthat/_snaps/sector_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# at product level, Tilman's example yields what he expects

Code
product
Output
# A tibble: 5 x 11
companies_id grouped_by risk_category profile_ranking clustered
<chr> <chr> <chr> <dbl> <chr>
1 a ipr_a_2050 high 1 a
2 a weo_a_2050 medium 0.6 a
3 a <NA> <NA> NA b
4 a ipr_a_2050 low 0.3 c
5 a weo_a_2050 <NA> NA c
# i 6 more variables: activity_uuid_product_uuid <chr>, tilt_sector <chr>,
# scenario <chr>, year <dbl>, type <chr>, tilt_subsector <chr>

# at company level, Tilman's example yields what he expects

Code
product
Output
# A tibble: 5 x 5
companies_id grouped_by risk_category profile_ranking clustered
<chr> <chr> <chr> <dbl> <chr>
1 a ipr_a_2050 high 1 a
2 a weo_a_2050 medium 0.6 a
3 a <NA> <NA> NA b
4 a ipr_a_2050 low 0.3 c
5 a weo_a_2050 <NA> NA c

52 changes: 50 additions & 2 deletions tests/testthat/test-sector_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,54 @@ test_that("at product level, given a `clustered` matching one but not a second `
expect_true("weo_w_2050" %in% product$grouped_by)
})

test_that("xxxxxx", {
expect_equal("TODO", "test cases 'a' and 'b' at product level")
test_that("at product level, Tilman's example yields what he expects", {
# https://docs.google.com/spreadsheets/d/16u9WNtVY-yDsq6kHANK3dyYGXTbNQ_Bn/edit#gid=156243064
# styler: off
companies <- tribble(
~companies_id, ~clustered, ~activity_uuid_product_uuid, ~tilt_sector, ~tilt_subsector, ~type, ~sector, ~subsector,
"a", "a", "a", "a", "a", "ipr", "total", "energy",
"a", "a", "a", "a", "a", "weo", "total", "energy",
"a", "b", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched",
"a", "c", "unmatched", "c", "c", "ipr", "land use", "land use",
"a", "c", "unmatched", "c", "c", "weo", NA, NA
)
scenarios <- tribble(
~sector, ~subsector, ~year, ~reductions, ~type, ~scenario,
"total", "energy", 2050, 1.0, "ipr", "a",
"total", "energy", 2050, 0.6, "weo", "a",
"land use", "land use", 2050, 0.3, "ipr", "a"
)
# styler: off

# FIXME: Change for something less brittle
product <- sector_profile(companies, scenarios) |>
unnest_product() |>
arrange(clustered)

expect_snapshot(product)
})

test_that("at company level, Tilman's example yields what he expects", {
# https://docs.google.com/spreadsheets/d/16u9WNtVY-yDsq6kHANK3dyYGXTbNQ_Bn/edit#gid=156243064
# styler: off
companies <- tribble(
~companies_id, ~clustered, ~activity_uuid_product_uuid, ~tilt_sector, ~tilt_subsector, ~type, ~sector, ~subsector,
"a", "a", "a", "a", "a", "ipr", "total", "energy",
"a", "a", "a", "a", "a", "weo", "total", "energy",
"a", "b", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched",
"a", "c", "unmatched", "c", "c", "ipr", "land use", "land use",
"a", "c", "unmatched", "c", "c", "weo", NA, NA
)
scenarios <- tribble(
~sector, ~subsector, ~year, ~reductions, ~type, ~scenario,
"total", "energy", 2050, 1.0, "ipr", "a",
"total", "energy", 2050, 0.6, "weo", "a",
"land use", "land use", 2050, 0.3, "ipr", "a"
)
# styler: off

company <- sector_profile(companies, scenarios) |> unnest_company()

# FIXME: Change for something less brittle
expect_snapshot(product)
})

0 comments on commit bb7c2a2

Please sign in to comment.