Skip to content

Commit

Permalink
Works with two companies
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed May 16, 2024
1 parent 3ebf200 commit c1a8a5a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/testthat/test-sector_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,43 @@ test_that("works with Tilman's example case 'c': match one", {
sort()
expect_equal(value, 1)
})

test_that("at product level, Tilman's example with two companies 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,

"b", "a", "a", "a", "a", "ipr", "total", "energy",
"b", "a", "a", "a", "a", "weo", "total", "energy",
"b", "b", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched",
"b", "c", "unmatched", "c", "c", "ipr", "land use", "land use",
"b", "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: on

product <- sector_profile(companies, scenarios) |> unnest_product()
expect_equal(
product |> filter(companies_id == "a") |> select(-companies_id),
product |> filter(companies_id == "b") |> select(-companies_id)
)

company <- sector_profile(companies, scenarios) |> unnest_company()
expect_equal(
company |> filter(companies_id == "a") |> select(-companies_id),
company |> filter(companies_id == "b") |> select(-companies_id)
)
})

# TODO: Preserves row-order

0 comments on commit c1a8a5a

Please sign in to comment.