Skip to content

Commit

Permalink
test-more
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed May 14, 2024
1 parent ad9d39f commit cedc0c9
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions tests/testthat/test-sector_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ test_that("at product level, when a single product matches by `sector`, `subsect
})

test_that("at product level, when a single product is unmatched by `type`, `sector`, or `subsector`, then `risk_category`, and `profile_ranking` are `NA`", {
# Relevan row in Tilman's test-data:
# https://docs.google.com/spreadsheets/d/16u9WNtVY-yDsq6kHANK3dyYGXTbNQ_Bn/edit#gid=156243064&range=A5:I5
# styler: off
# Starting with a matched dataset, to later create different kinds of unmatched datasets
companies <- tribble(
~companies_id, ~clustered, ~activity_uuid_product_uuid, ~tilt_sector, ~tilt_subsector, ~type, ~sector, ~subsector,
"a", "b", "any", "any", "any", "ipr", "total", "energy",
Expand All @@ -163,8 +161,6 @@ test_that("at product level, when a single product is unmatched by `type`, `sect
)
# styler: on

# Relevant Tilman's expectations:
# https://docs.google.com/spreadsheets/d/16u9WNtVY-yDsq6kHANK3dyYGXTbNQ_Bn/edit#gid=156243064&range=B19:D19
col <- "type"
companies1 <- companies
companies1[[col]] <- "unmatched"
Expand Down Expand Up @@ -232,3 +228,39 @@ test_that("at company level, when a single product matches by `sector`, `subsect
values <- filter(company, !is.na(risk_category))$value
expect_equal(sort(values), c(0, 0, 1))
})

test_that("at company level, when a single product is unmatched by `type`, `sector`, or `subsector`, then the `value` is 1 where `risk_category` is `NA` and it is 0 for every other `risk_category`", {
# Starting with a matched dataset, to later create different kinds of unmatched datasets
companies <- tribble(
~companies_id, ~clustered, ~activity_uuid_product_uuid, ~tilt_sector, ~tilt_subsector, ~type, ~sector, ~subsector,
"a", "b", "any", "any", "any", "ipr", "total", "energy",
)

scenarios <- tribble(
~sector, ~subsector, ~year, ~reductions, ~type, ~scenario,
"total", "energy", 2050, 1.0, "ipr", "a",
)
# styler: on

col <- "type"
companies1 <- companies
companies1[[col]] <- "unmatched"
company <- sector_profile(companies1, scenarios) |> unnest_company()
expect_equal(filter(company, is.na(risk_category))$value, 1L)
expect_equal(filter(company, !is.na(risk_category))$value, c(0, 0, 0))

col <- "sector"
companies1 <- companies
companies1[[col]] <- "unmatched"
company <- sector_profile(companies1, scenarios) |> unnest_company()
expect_equal(filter(company, is.na(risk_category))$value, 1L)
expect_equal(filter(company, !is.na(risk_category))$value, c(0, 0, 0))

col <- "subsector"
companies1 <- companies
companies1[[col]] <- "unmatched"
company <- sector_profile(companies1, scenarios) |> unnest_company()
expect_equal(filter(company, is.na(risk_category))$value, 1L)
expect_equal(filter(company, !is.na(risk_category))$value, c(0, 0, 0))
})

0 comments on commit cedc0c9

Please sign in to comment.