tests/testthat/test-summarise_vp_flow_all_years.R

context("Testing `summarise_vp_flow_all_years()`")

pkg_data <-
  system.file("extdata", "virtual-pollinators-flow.qs", package = "vbpflow")

df <-
  qread(pkg_data)

# xpectr::gxs_selection("summarise_vp_flow_all_years(df)")

## Testing 'summarise_vp_flow_all_years(df)'                                ####
## Initially generated by xpectr
xpectr::set_test_seed(42)
# Assigning output
output_19148 <- summarise_vp_flow_all_years(df)
# Testing class
expect_equal(
  class(output_19148),
  c("tbl_df", "tbl", "data.frame"),
  fixed = TRUE
)
# Testing column values
expect_equal(
  xpectr::smpl(output_19148[["reporter_countries"]], n = 30),
  c(
    "India", "Switzerland", "Estonia", "Jamaica", "Kazakhstan", "Chile",
    "Singapore", "Indonesia", "Hong Kong S.A.R.", "Argentina", "Burkina Faso",
    "Denmark", "Burkina Faso", "United Kingdom", "Thailand", "Kazakhstan",
    "Sweden", "Honduras", "Tunisia", "Ecuador", "Albania", "Uganda",
    "Luxembourg", "Latvia", "Croatia", "Ecuador", "Argentina", "Latvia",
    "Canada", "Italy"
  ),
  fixed = TRUE
)
expect_equal(
  xpectr::smpl(output_19148[["partner_countries"]], n = 30),
  c(
    "Bolivia", "Bosnia and Herzegovina", "Saint Vincent and the Grenadines",
    "Singapore", "Saint Helena", "Mauritius", "Malta", "Belarus",
    "Spain", "Macedonia", "Greece", "Haiti", "Spain", "Hong Kong S.A.R.",
    "France", "Pakistan", "France", "Norway", "United Arab Emirates",
    "United Kingdom", "Montenegro", "Singapore", "Germany", "Netherlands",
    "Republic of Serbia", "Belgium", "Israel", "Lithuania", "Pakistan",
    "Austria"
  ),
  fixed = TRUE
)
expect_equal(
  xpectr::smpl(output_19148[["reporter_long"]], n = 30),
  c(
    79.61198, 8.20867, 25.54249, -77.31483, 67.29149, -71.38256, 103.81726,
    117.24011, 114.1138, -65.17981, -1.75457, 10.02801, -1.75457,
    -2.86563, 101.00288, 67.29149, 16.74558, -86.61517, 9.55288,
    -78.75202, 20.04983, 32.36908, 6.07182, 24.91236, 16.40413,
    -78.75202, -65.17981, 24.91236, -98.30777, 12.07001
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["reporter_lat"]], n = 30),
  c(
    22.88578, 46.79786, 58.67193, 18.15695, 48.15688, -37.73071, 1.35876,
    -2.21505, 22.39828, -35.38135, 12.26954, 55.98125, 12.26954,
    54.12387, 15.11816, 48.15688, 62.77967, 14.82688, 34.11956,
    -1.42382, 41.14245, 1.27469, 49.76725, 56.85085, 45.08048, -1.42382,
    -35.38135, 56.85085, 61.36206, 42.79663
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["reporter_hdi"]], n = 30),
  c(
    0.5626, 0.9182, 0.8356, 0.7042, 0.75687, 0.80093, 0.8828, 0.65033,
    0.88707, 0.7978, 0.35313, 0.90793, 0.35313, 0.89533, 0.70667,
    0.75687, 0.90613, 0.58713, 0.70087, 0.70767, 0.72727, 0.4632,
    0.8826, 0.8072, 0.79773, 0.70767, 0.7978, 0.8072, 0.8976, 0.86293
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["partner_long"]], n = 30),
  c(
    -64.68539, 17.76877, -61.2013, 103.81726, -9.54779, 57.57121,
    14.40523, 28.03209, -3.64755, 21.68211, 22.95556, -72.68528,
    -3.64755, 114.1138, -2.76173, 69.33958, -2.76173, 15.34835,
    54.30017, -2.86563, 19.23884, 103.81726, 10.38578, 5.28145,
    20.78958, 4.64065, 35.00445, 23.88719, 69.33958, 14.12648
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["partner_lat"]], n = 30),
  c(
    -16.70815, 44.1745, 13.22472, 1.35876, -12.40356, -20.27769, 35.9215,
    53.53131, 40.24449, 41.59531, 39.0747, 18.93503, 40.24449, 22.39828,
    42.17344, 29.94975, 42.17344, 68.75016, 23.90528, 54.12387,
    42.7889, 1.35876, 51.10698, 52.10079, 44.2215, 50.63982, 31.4611,
    55.32611, 29.94975, 47.58549
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["partner_hdi"]], n = 30),
  c(
    0.6422, 0.7152, 0.7056, 0.8828, 0, 0.73427, 0.82967, 0.75967,
    0.85567, 0.71793, 0.84613, 0.46633, 0.85567, 0.88707, 0.87527,
    0.511, 0.87527, 0.93607, 0.83293, 0.89533, 0.78177, 0.8828,
    0.91167, 0.90367, 0, 0.8964, 0.8806, 0.81747, 0.511, 0.8758
  ),
  tolerance = 1e-4
)
expect_equal(
  xpectr::smpl(output_19148[["vp_flow"]], n = 30),
  c(
    0.78109, 1.49295, 1.99237, 2.12816, 9.59768, 13.50054, 38.3087,
    71.51181, 80.56767, 84.61936, 97.31219, 153.02402, 163.68754,
    270.31415, 694.09969, 818.73369, 1467.6149, 1772.90573, 2266.96987,
    9270.15019, 10044.50097, 36455.8252, 37559.25034, 48994.67782,
    78194.14496, 84882.96906, 87560.11374, 103713.12972, 361122.34041,
    614788.16637
  ),
  tolerance = 1e-4
)
# Testing column names
expect_equal(
  names(output_19148),
  c(
    "reporter_countries", "partner_countries", "reporter_long", "reporter_lat",
    "reporter_hdi", "partner_long", "partner_lat", "partner_hdi",
    "vp_flow"
  ),
  fixed = TRUE
)
# Testing column classes
expect_equal(
  xpectr::element_classes(output_19148),
  c(
    "character", "character", "numeric", "numeric", "numeric", "numeric",
    "numeric", "numeric", "numeric"
  ),
  fixed = TRUE
)
# Testing column types
expect_equal(
  xpectr::element_types(output_19148),
  c(
    "character", "character", "double", "double", "double", "double",
    "double", "double", "double"
  ),
  fixed = TRUE
)
# Testing dimensions
expect_equal(
  dim(output_19148),
  c(11386L, 9L)
)
# Testing group keys
expect_equal(
  colnames(dplyr::group_keys(output_19148)),
  character(0),
  fixed = TRUE
)
## Finished testing 'summarise_vp_flow_all_years(df)'                       ####
virtual-pollination-trade/virtual-biotic-pollination-flow documentation built on May 3, 2021, 4:40 p.m.