2DegreesInvesting / tiltIndicatorAfter

Process indicator results so that they are closer to the user-facing outputs
https://2degreesinvesting.github.io/tiltIndicatorAfter/
GNU General Public License v3.0
0 stars 0 forks source link

Make test-friendly data fakes #35

Closed maurolepore closed 1 year ago

maurolepore commented 1 year ago

Once we define the critical data (e.g. crucial columns) it'll help to create test-data constructors that are as minimal as possible.

Here is one silly example:

new_fake_dataset <- function(id = 1, other = "b", ...) {
  tibble::tibble(id = id, other = other, ...)
}

new_fake_dataset()
#> # A tibble: 1 × 2
#>      id other
#>   <dbl> <chr>
#> 1     1 b

new_fake_dataset(id = 1:2)
#> # A tibble: 2 × 2
#>      id other
#>   <int> <chr>
#> 1     1 b    
#> 2     2 b

new_fake_dataset(id = 1:2, new = "z")
#> # A tibble: 2 × 3
#>      id other new  
#>   <int> <chr> <chr>
#> 1     1 b     z    
#> 2     2 b     z

Created on 2023-09-21 with reprex v2.0.2

https://r-pkgs.org/testing-advanced.html#sec-testing-advanced-fixture-helper

maurolepore commented 1 year ago

Relates to https://github.com/2DegreesInvesting/tiltIndicatorAfter/pull/55

We now have some toy_*() datasets, and I plan to add more as needed.

library(tiltIndicator)
library(tiltIndicatorAfter)

toy_sector_profile_result() |> unnest_company()
#> # A tibble: 588 × 4
#>    companies_id                             grouped_by       risk_category value
#>    <chr>                                    <chr>            <chr>         <dbl>
#>  1 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… high              1
#>  2 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… medium            0
#>  3 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… low               0
#>  4 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… high              1
#>  5 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… medium            0
#>  6 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_20… low               0
#>  7 fleischerei-stiefsohn_00000005219477-001 weo_announced p… high              0
#>  8 fleischerei-stiefsohn_00000005219477-001 weo_announced p… medium            0
#>  9 fleischerei-stiefsohn_00000005219477-001 weo_announced p… low               1
#> 10 fleischerei-stiefsohn_00000005219477-001 weo_announced p… high              0
#> # ℹ 578 more rows

toy_sector_profile_upstream_result() |> unnest_company()
#> # A tibble: 14 × 4
#>    companies_id                             grouped_by risk_category value
#>    <chr>                                    <chr>      <chr>         <dbl>
#>  1 fleischerei-stiefsohn_00000005219477-001 <NA>       <NA>             NA
#>  2 pecheries-basques_fra316541-00101        <NA>       <NA>             NA
#>  3 hoche-butter-gmbh_deu422723-693847001    <NA>       <NA>             NA
#>  4 hoche-butter-gmbh_deu422723-693847002    <NA>       <NA>             NA
#>  5 hoche-butter-gmbh_deu422723-693847003    <NA>       <NA>             NA
#>  6 vicquelin-espaces-verts_fra697272-00101  <NA>       <NA>             NA
#>  7 vicquelin-espaces-verts_fra697272-00102  <NA>       <NA>             NA
#>  8 vicquelin-espaces-verts_fra697272-00103  <NA>       <NA>             NA
#>  9 fleisohn_0000000492-001                  <NA>       <NA>             NA
#> 10 bst-procontrol-gmbh_00000005104947-001   <NA>       <NA>             NA
#> 11 leider-gmbh_00000005064318-001           <NA>       <NA>             NA
#> 12 leider-gmbh_00000005064318-002           <NA>       <NA>             NA
#> 13 cheries-baqu_neu316541-00101             <NA>       <NA>             NA
#> 14 ca-coity-trg-aua-gmbh_00000384-001       <NA>       <NA>             NA
maurolepore commented 1 year ago

Closing until the need for more datasets arises.